I am trying to iterate and retrieve the policies about all S3 buckets in an account.
I am trying the following...
s3 = boto3.client('s3')
buckets = s3.list_buckets()
for bucket_name in buckets['Buckets']:
s3.get_bucket_policy(Bucket=bucket_name['Name'])
When I run this, I get the following error:
botocore.exceptions.ClientError: An error occurred (PermanentRedirect) when calling the GetBucketTagging operation: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
I've tried used s3.meta.client.get_bucket_location(Bucket=bucket_name['Name'])
as per https://github.com/boto/boto3/issues/81, but I get a value of None
for 'LocationConstraint'
.
How can I know or ascertain the correct endpoint and/or region for an arbitrary bucket?