Usar GetBucketLocation
com o AWS SDK ou a CLI
Os exemplos de código a seguir mostram como usar o GetBucketLocation
.
- CLI
-
- AWS CLI
-
O seguinte comando recupera a restrição de localização do bucket
my-bucket
, se houver uma restrição:aws s3api get-bucket-location --bucket my-bucket
Saída:
{ "LocationConstraint": "us-west-2" }
-
Para obter detalhes da API, consulte GetBucketLocation
na Referência de comandos da AWS CLI.
-
- PowerShell
-
- Tools for PowerShell
-
Exemplo 1: se houver uma restrição, este comando retornará a restrição de localização do bucket “s3testbucket”.
Get-S3BucketLocation -BucketName 's3testbucket'
Saída:
Value ----- ap-south-1
-
Para obter detalhes da API, consulte GetBucketLocation na AWS Tools for PowerShell Cmdlet Reference.
-
- Rust
-
- SDK para Rust
-
nota
Há mais no GitHub. Encontre o exemplo completo e saiba como configurar e executar no Repositório de exemplos de código da AWS
. async fn show_buckets(strict: bool, client: &Client, region: &str) -> Result<(), Error> { let resp = client.list_buckets().send().await?; let buckets = resp.buckets(); let num_buckets = buckets.len(); let mut in_region = 0; for bucket in buckets { if strict { let r = client .get_bucket_location() .bucket(bucket.name().unwrap_or_default()) .send() .await?; if r.location_constraint().unwrap().as_ref() == 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(()) }
-
Para obter detalhes da API, consulte GetBucketLocation
na Referência da API AWS SDK para Rust.
-
Para ver uma lista completa dos Guias do desenvolvedor de SDK da AWS e exemplos de código, consulte Usar este serviço com um AWS SDK. Este tópico também inclui informações sobre como começar e detalhes sobre versões anteriores do SDK.