Skip to content

Instantly share code, notes, and snippets.

@2XXE-SRA
Created October 29, 2019 00:48
Show Gist options
  • Save 2XXE-SRA/c9e4edfa6e92cf21a6899576012ab4b0 to your computer and use it in GitHub Desktop.
Save 2XXE-SRA/c9e4edfa6e92cf21a6899576012ab4b0 to your computer and use it in GitHub Desktop.
Get S3 bucket region anonymously via boto3
import boto3
from botocore import UNSIGNED
from botocore.client import Config
s3 = boto3.client('s3', config=Config(signature_version=UNSIGNED))
s3.head_bucket(Bucket="bucketname")
print(s3.head_bucket(Bucket="flaws.cloud")["ResponseMetadata"]["HTTPHeaders"]["x-amz-bucket-region"]) # output: us-west-2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment