Gunakan GetBucketLocation dengan AWS SDK atau CLI - AWS Contoh Kode SDK

Ada lebih banyak contoh AWS SDK yang tersedia di repo Contoh SDK AWS Doc. GitHub

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Gunakan GetBucketLocation dengan AWS SDK atau CLI

Contoh kode berikut menunjukkan cara menggunakanGetBucketLocation.

CLI
AWS CLI

Perintah berikut mengambil batasan lokasi untuk bucket bernamamy-bucket, jika ada kendala:

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

Output:

{ "LocationConstraint": "us-west-2" }
PowerShell
Alat untuk PowerShell

Contoh 1: Perintah ini mengembalikan batasan lokasi untuk bucket 's3testbucket', jika ada kendala.

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

Output:

Value ----- ap-south-1
  • Untuk detail API, lihat GetBucketLocationdi Referensi AWS Tools for PowerShell Cmdlet.

Rust
SDK untuk Rust
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode 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(()) }