KommonMan
KommonMan

Reputation: 29

Amazon S3 Permission Errors 403, simple upload of a text file

So I have been using several different tutorials in stackoverflow and they all seem to come to the same error: 403 Permission denied.

I am using python2.7 and boto on ubuntu 14.04.

Below is the code (without the keys and bucket name) and I would like to know why I am being denied access to my own bucket.

I created a user in IAM that has complete access to S3, and I set the permissions on the bucket to allow 'Everyone' to upload/download. I am using the correct keys because I copied and pasted them into the code.

Could this have something to do with bucket policy? Or is there something I am not aware of? I am new to this and only need this to upload and download text files on S3.

import boto
from boto.s3.key import Key
import boto.s3.connection

AWS_ACCESS_KEY_ID = ''
AWS_SECRET_ACCESS_KEY = ''
Bucketname = '' 
conn = boto.connect_s3(aws_access_key_id=AWS_ACCESS_KEY_ID,
       aws_secret_access_key=AWS_SECRET_ACCESS_KEY )

bucket = conn.get_bucket(Bucketname)

Upvotes: 1

Views: 752

Answers (1)

KommonMan
KommonMan

Reputation: 29

The comment was helpful, thank you FirebladeDan. So I created a user that has Admin Access, and full S3 access. That was all done in IAM. Now in the bucket properties I added a permission set to a Grantee 'Everyone' allowing them to upload/download and list. Now the last step was to add a bucket policy. I didn't think I needed to do that and so I posted here.

I was wrong. So here is what I used. NOTE: This allows me to upload to S3, however most of the time set_contents_from_filename() only uploads the header and doesn't always upload the file. This is probably an error in my code, but should you be experiencing the same thing then this policy might need extra permissions of some sort.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "USERNAME",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::GETNUMBERSOFUSER:root"
            },
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::BUCKETNAME",
                "arn:aws:s3:::BUCKETNAME/*"
            ]
        }
    ]
}

Upvotes: 1

Related Questions