boto / boto3

AWS SDK for Python
https://aws.amazon.com/sdk-for-python/
Apache License 2.0
9.07k stars 1.87k forks source link

head_bucket returns ResponseMetadata without BucketRegion #4191

Closed daeho-ro closed 4 months ago

daeho-ro commented 4 months ago

Describe the bug

Hello, I want to know the bucket location and so I used head_bucket for s3 client.

s3.head_bucket(Bucket='BucketName')

and I received ResponseMetadata as follows:

{'ResponseMetadata': {'RequestId': 'CQDWDY0TWKXA840Y', 'HostId': 'IBUaQ0NicjPCbuT/qaRww6HowsPrFuocTfG1TSrmO1K1zStoJTyzruB/Hd4apDCMBPJ2A7x/7HE=', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amz-id-2': 'IBUaQ0NicjPCbuT/qaRww6HowsPrFuocTfG1TSrmO1K1zStoJTyzruB/Hd4apDCMBPJ2A7x/7HE=', 'x-amz-request-id': 'CQDWDY0TWKXA840Y', 'date': 'Tue, 09 Jul 2024 06:57:44 GMT', 'x-amz-bucket-region': 'us-east-1', 'x-amz-access-point-alias': 'false', 'content-type': 'application/xml', 'server': 'AmazonS3'}, 'RetryAttempts': 0}}

You cannot find the BucketRegion key even though the response indicates the status code 200. This is only happen when I run the code on the us-east-1 region of AWS lambda.

Expected Behavior

It should somehow contains the 'BucketRegion': 'us-east-1' key and value in the response dict.

Current Behavior

It does not contain BucketRegion key.

Reproduction Steps

Simply write the code to call head_bucket method and deploy to the region us-east-1 of AWS Lambda, run the code.

Possible Solution

No response

Additional Information/Context

No response

SDK version used

Installed on docker build, maybe latest

Environment details (OS name and version, etc.)

Docker on public.ecr.aws/lambda/python:3.11.2023.07.13.17-arm64

tim-finnigan commented 4 months ago

Hi @daeho-ro thanks for reaching out. I tried to reproduce this for buckets in us-east-1 and us-west-2, but I received BucketRegion in the response for both. The head_bucket Boto3 command involves a call to the S3 HeadObject API and is returning the response from the API. If you are seeing results that are inconsistent with the documentation, then you may be using an older version of Boto3.

Which version of Boto3 are you using? The latest is 1.34.142, we recommend updating to a recent version if possible. You can find instructions on bundling a recent copy of Boto3 in Lambda here.

If still seeing the issue after updating, please share your debug logs (with sensitive info redacted) by adding boto3.set_stream_logger('') to your script.

daeho-ro commented 4 months ago

Indeed, the version is key. I have used the docker image public.ecr.aws/lambda/python:3.11.2023.07.13.17-arm64 and as you noticed that the date is not that recent. So I have changed the tag without date 3.11-arm64 and finally got correct answer.

Thanks, @tim-finnigan

github-actions[bot] commented 4 months ago

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.