Reputation: 2042
I'm trying to list buckets following the boto3 documentation.
import boto3
s3 = boto3.client(service_name = 's3',
region_name = 'us-east-2',
aws_access_key_id='xxxxxx',
aws_secret_access_key= 'xxxxx'
)
response = s3.list_buckets()
# Output the bucket names
print('Existing buckets:')
for bucket in response['Buckets']:
print(f' {bucket["Name"]}')
But it turns out with an error, which says
ClientError: An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied
I found some similar posts for this error, but I still don't know how to fix mine. Any help would be appreciated.
Upvotes: 3
Views: 2454
Reputation: 80
I tried to run your code and everything worked properly. And you don't have to specify region_name 'cause anyway you will get all buckets. And then I tried to remove permission to s3 from my user and got the same error. I guess you're getting such an error because of your user's policy. You should attach content of your policy to the question.
Upvotes: 1