View a markdown version of this page

Utilizzare GetBucketLocationcon un AWS SDK o CLI - Amazon Simple Storage Service

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Utilizzare GetBucketLocationcon un AWS SDK o CLI

Gli esempi di codice seguenti mostrano come utilizzare GetBucketLocation.

CLI
AWS CLI

Il comando seguente recupera il vincolo di posizione per un bucket denominato amzn-s3-demo-bucket, se esiste un vincolo.

aws s3api get-bucket-location --bucket amzn-s3-demo-bucket

Output:

{ "LocationConstraint": "us-west-2" }
PowerShell
Strumenti per PowerShell V4

Esempio 1: questo comando restituisce il vincolo di posizione eventualmente presente per il bucket “amzn-s3-demo-bucket.

Get-S3BucketLocation -BucketName 'amzn-s3-demo-bucket'

Output:

Value ----- ap-south-1
  • Per i dettagli sull'API, vedere GetBucketLocationin AWS Strumenti per PowerShell Cmdlet Reference (V4).

Strumenti per V5 PowerShell

Esempio 1: questo comando restituisce il vincolo di posizione eventualmente presente per il bucket “amzn-s3-demo-bucket.

Get-S3BucketLocation -BucketName 'amzn-s3-demo-bucket'

Output:

Value ----- ap-south-1
  • Per i dettagli sull'API, vedere GetBucketLocationin AWS Strumenti per PowerShell Cmdlet Reference (V5).

Rust
SDK per Rust
Nota

C'è altro da fare. GitHub Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

async fn show_buckets( strict: bool, client: &Client, region: BucketLocationConstraint, ) -> Result<(), S3ExampleError> { let mut buckets = client.list_buckets().into_paginator().send(); let mut num_buckets = 0; let mut in_region = 0; while let Some(Ok(output)) = buckets.next().await { for bucket in output.buckets() { num_buckets += 1; if strict { let r = client .get_bucket_location() .bucket(bucket.name().unwrap_or_default()) .send() .await?; if r.location_constraint() == Some(&region) { println!("{}", bucket.name().unwrap_or_default()); in_region += 1; } } else { println!("{}", bucket.name().unwrap_or_default()); } } } println!(); if strict { println!( "Found {} buckets in the {} region out of a total of {} buckets.", in_region, region, num_buckets ); } else { println!("Found {} buckets in all regions.", num_buckets); } Ok(()) }
  • Per i dettagli sulle API, consulta la GetBucketLocationguida di riferimento all'API AWS SDK for Rust.

Per un elenco completo delle guide per sviluppatori AWS SDK e degli esempi di codice, consulta. Sviluppo con Amazon S3 utilizzando AWS SDK Questo argomento include anche informazioni su come iniziare e dettagli sulle versioni precedenti dell’SDK.