Usar GetBucketLocation com um SDK da AWS ou uma ferramenta de linha de comandos - Amazon Simple Storage Service

Usar GetBucketLocation com um SDK da AWS ou uma ferramenta de linha de comandos

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 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: este comando retorna a restrição de localização do bucket “s3testbucket”, se houver uma restrição.

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 for 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: &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 do AWS SDK para Rust.

Para obter uma lista completa dos guias do desenvolvedor do 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.