Uso de GetBucketLocation con un AWS SDK o una CLI - Amazon Simple Storage Service

Uso de GetBucketLocation con un AWS SDK o una CLI

En los siguientes ejemplos de código, se muestra cómo utilizar GetBucketLocation.

CLI
AWS CLI

El siguiente comando recupera la restricción de ubicación de un bucket denominado my-bucket, si existe una restricción:

aws s3api get-bucket-location --bucket my-bucket

Salida:

{ "LocationConstraint": "us-west-2" }
  • Para obtener información sobre la API, consulte GetBucketLocation en la Referencia de comandos de la AWS CLI.

PowerShell
Herramientas para PowerShell

Ejemplo 1: este comando devuelve la restricción de ubicación del bucket “s3testbucket”, si existe una restricción.

Get-S3BucketLocation -BucketName 's3testbucket'

Salida:

Value ----- ap-south-1
  • Para obtener información sobre la API, consulte GetBucketLocation en la Referencia de Cmdlet de AWS Tools for PowerShell.

Rust
SDK para Rust
nota

Hay más información en GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de 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(()) }
  • Para obtener información sobre la API, consulte GetBucketLocation en la Referencia de la API de AWS SDK para Rust.

Para obtener una lista completa de las guías para desarrolladores del AWS SDK y ejemplos de código, consulte Uso de este servicio con un SDK de AWS. En este tema también se incluye información sobre cómo comenzar a utilizar el SDK y detalles sobre sus versiones anteriores.