Get the Region where the Amazon S3 bucket resides using an Amazon SDK - Amazon Simple Storage Service
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

Get the Region where the Amazon S3 bucket resides using an Amazon SDK

The following code example shows how to get the Region location for an S3 bucket.

SDK for Rust

This documentation is for an SDK in preview release. The SDK is subject to change and should not be used in production.


There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code 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().unwrap_or_default(); let num_buckets = buckets.len(); let mut in_region = 0; for bucket in buckets { if strict { let r = client .get_bucket_location() .bucket( .send() .await?; if r.location_constraint().unwrap().as_ref() == region { println!("{}",; in_region += 1; } } else { println!("{}",; } } 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(()) }

For a complete list of Amazon SDK developer guides and code examples, see Using this service with an Amazon SDK. This topic also includes information about getting started and details about previous SDK versions.