ITADN

(aws) s3: get_bucket_location is no longer recommended by boto3

#2508Openaliahmed58 创建于 2026-03-17
A
aliahmed58commented
## S3 `get_bucket_location` is no longer recommended to fetch bucket's region ### Expected behavior The `Region` property for every bucket should be set when the bucket list is being fetched in `get_s3_bucket_list`. ### Actual behavior The `Region` property for some buckets is set to `None` due to the API `get_bucket_location` returning null as explained in the [note section of boto3 S3 docs](https://docs.aws.amazon.com/boto3/latest/reference/services/s3/client/get_bucket_location.html). > In a bucket’s home Region, calls to the GetBucketLocation operation are governed by the bucket’s policy. In other Regions, the bucket policy doesn’t apply, which means that cross-account access won’t be authorized. However, calls to the HeadBucket operation always return the bucket’s location through an HTTP response header, whether access to the bucket is authorized or not. Therefore, we recommend using the HeadBucket operation for bucket Region discovery and to avoid using the GetBucketLocation operation. This can be fixed by calling [HeadBucket](https://docs.aws.amazon.com/AmazonS3/latest/API/API_HeadBucket.html) instead and accessing the region from `BucketRegion` key in response. ### Please complete the following information: - Commit hash: 9b19e0054df6ce4523876964dfbe23b973816583 - Python version: 3.10.20
0 条评论