2

I get this error in terminal when I try to list all the buckets using boto3: An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied.

Here's the code:

for bucket in s3.buckets.all():
    print(bucket.name)

I found a stack overflow question (Why is my terminal returning this s3 error?) and below is the proposed solution. I'm very unfamiliar with AWS so I need a bit of guidance.

Where can I find the dictionary inside like the one below inside the AWS console?

{
"Sid": "AllowListingOfAllBuckets",
"Effect": "Allow",
"Action": [
    "s3:ListAllMyBuckets"
],
"Resource": [
    "arn:aws:s3:::*"
]
}
Community
  • 1
  • 1
rocky raccoon
  • 514
  • 1
  • 8
  • 23
  • 1
    S3 console, select the bucket and view the properties. Add a bucket policy. Alternatively, set those permissions on the IAM user or role your Boto3 code is using. – Mark B Mar 06 '17 at 18:33

1 Answers1

1

you may add the following to the Actions array in the policy: s3:ListBucket

{
    "Sid": "AllowListingOfAllBuckets",
    "Effect": "Allow",
    "Action": [
       "s3:ListAllMyBuckets",
       "s3:ListBuckets",
    ],
    "Resource": [
       "arn:aws:s3:::*"
    ]
}

You may need to update the Resource: "Resource": "arn:aws:s3:::mywebsite.media/*"