Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why might boto be denied access to S3 with proper IAM keys?

I am trying to access a bucket on S3 with boto. I have been given read access to the bucket and my keys are working when I explore it in S3 Browser. The following code is returning 403 Forbidden Access Denied.

conn = S3Connection('Access_Key_ID', 'Secret_Access_Key')
conn.get_all_buckets()

This also occurs when using the access key and secret access key via the boto config file. Is there something else I need to be doing because the keys are from IAM perhaps? Could this indicate an error in the setup? I don't know much about IAM, I was just given the keys.

like image 387
rhnoble Avatar asked Sep 13 '12 17:09

rhnoble


People also ask

Why is my S3 Access Denied?

If you're getting Access Denied errors on public read requests that are allowed, check the bucket's Amazon S3 Block Public Access settings. Review the S3 Block Public Access settings at both the account and bucket level. These settings can override permissions that allow public read access.

Why am I getting an access denied error from the Amazon S3 console when I try to modify a bucket policy?

Short description. The "403 Access Denied" error can occur due to the following reasons: Your AWS Identity and Access Management (IAM) user or role doesn't have permissions for both s3:GetBucketPolicy and s3:PutBucketPolicy.


2 Answers

Some things to check...

  • If you are using boto, be sure you are using conn.get_bucket(bucket_name) to access only the bucket you have permission to access.

  • In your IAM (user) policy, if you are restricting access to a single bucket, be sure that the policy includes adequate permissions to the bucket and do not include a trailing slash+asterisks for the ARN name (see example below).

  • Be sure to set "Upload/Delete" permissions for "Authenticated Users" in S3 for the bucket.

Permissions sample:

enter image description here

IAM policy sample:

NOTE: The SID will be automatically generated when using the policy generator

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "s3:*"
      ],
      "Sid": "Stmt0000000000001",
      "Resource": [
        "arn:aws:s3:::myBucketName"
      ],
      "Effect": "Allow"
    }
  ]
}
like image 70
Vyke Avatar answered Sep 30 '22 17:09

Vyke


My guess is that it's because you're calling conn.get_all_buckets() instead of conn.get_bucket(bucket_name) for the individual bucket you have access to.

like image 25
user59200 Avatar answered Sep 30 '22 17:09

user59200