Define S3 Bucket Area
I am using AWS Ruby SDK v2 to access various buckets across multiple regions. Is it possible to define the scope (at runtime) of each bucket before I get it, so I can avoid the below error I get if I configure an AWS S3 client with the wrong region?
The bucket you are trying to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
I know I can lay out the shell and use the below command and parse the response, but ideally I want to stay in the Ruby SDK.
aws s3api get-bucket-location
source to share
I couldn't find an official doc for this, but from the aws-sdk spec you should be able to use the following code to get the scope
client = Aws::S3::Client.new()
resp = client.get_bucket_location(bucket: bucket_name)
s3_region = resp.data.location_constraint
This call calls the same API as aws s3api get-bucket-location
source to share