Utilizzare GetBucketLocation con un AWS SDKo 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 GetBucketLocation con un AWS SDKo CLI

I seguenti esempi di codice mostrano come utilizzareGetBucketLocation.

CLI
AWS CLI

Il comando seguente recupera il vincolo di posizione per un bucket denominatomy-bucket, se esiste un vincolo:

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

Output:

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

Esempio 1: questo comando restituisce il vincolo di posizione per il bucket 's3testbucket', se esiste un vincolo.

Get-S3BucketLocation -BucketName 's3testbucket'

Output:

Value ----- ap-south-1
  • GetBucketLocationPer i dettagli, vedere in API AWS Tools for PowerShell Riferimento al cmdlet.

Rust
SDKper Rust
Nota

c'è altro da fare GitHub. Trova l'esempio completo e scopri come configurare ed eseguire in AWS Repository di esempi di codice.

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 un elenco completo di AWS SDKguide per sviluppatori ed esempi di codice, vediUtilizzo di questo servizio con un SDK AWS. Questo argomento include anche informazioni su come iniziare e dettagli sulle SDK versioni precedenti.