I’m interacting directly with the AWS API not through a language specific library.
I’m trying to call ListObjectsV2 on a bucket and getting back an error message:
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>AuthorizationHeaderMalformed</Code>
<Message>The authorization header is malformed; the region 'us-east-1' is wrong; expecting 'eu-west-2'</Message>
<Region>eu-west-2</Region>
<RequestId>3W75CR8BNRQJ13Y6</RequestId>
<HostId>kYvjGFpckmTBxcq89h3Y+dWmt7UrHJWXlOQyr0k9V2/07NJVDK4dwg2rqAayjOwV1P4Z5bFnvys=</HostId>
</Error>
This seems logical enough, I know the bucket I’m trying to interact with at the moment is eu-west-2
.
My question is, if I didn’t know a bucket’s region, how could I find out through the API? Sigv4 requires you to specify the region, but if you don’t know it, how can you construct a request to find out?
This is for private buckets. I’ve found answers for public bucets but they don’t work for private buckets without authentication. And authentication requires you to know the region (AFAIK).
2
Answers
The bucket information is on its edit page, there you can get the location information.
And I had a problem with a script precisely because the aws-cli hadn’t put the locale.
There are three options.
For the first two, you can get the bucket region from the failure of a ListObjectsV2 call:
You can pull out the bucket location from either the
x-amz-bucket-region
HTTP header in the response, or from the XML response in theError.Region
node.Alternatively, you can place a HeadBucket call:
This includes the same
x-amz-bucket-region
header.These are the same three ways in the same order, that BotoCore uses when access S3 APIs.