View a markdown version of this page

Usar GetBucketLocation com o AWS SDK ou a CLI - Amazon Simple Storage Service

Usar GetBucketLocation com o AWS SDK ou a CLI

Os exemplos de código a seguir mostram como usar GetBucketLocation.

CLI
AWS CLI

O seguinte comando recupera a restrição de localização do bucket amzn-s3-demo-bucket, se houver uma restrição:

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

Resultado:

{ "LocationConstraint": "us-west-2" }
  • Consulte detalhes da API em GetBucketLocation na Referência de comandos da AWS CLI.

PowerShell
Ferramentas para PowerShell V4

Exemplo 1: se houver uma restrição, este comando retornará a restrição de localização do bucket “amzn-s3-demo-bucket.

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

Saída:

Value ----- ap-south-1
  • Consulte detalhes da API em GetBucketLocation na Referência de cmdlet do Ferramentas da AWS para PowerShell (V4).

Ferramentas para PowerShell V5

Exemplo 1: se houver uma restrição, este comando retornará a restrição de localização do bucket “amzn-s3-demo-bucket.

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

Saída:

Value ----- ap-south-1
  • Consulte detalhes da API em GetBucketLocation na Referência de cmdlet do Ferramentas da AWS para PowerShell (V5).

Rust
SDK para Rust
nota

Há mais no GitHub. Encontre o exemplo completo e saiba como configurar e executar no AWSCode Examples Repository.

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(()) }
  • Consulte detalhes da API em GetBucketLocation na Referência da API AWS SDK para Rust.

Para ver uma lista completa dos guias de desenvolvedor e exemplos de código do SDK da AWS, consulte Desenvolvimento com o Amazon S3 usando AWS SDKs. Este tópico também inclui informações sobre como começar e detalhes sobre versões anteriores do SDK.