Dan
Dan

Reputation: 147

How can I set up Amazon S3 bucket permission to an IAM user?

I want the IAM user to have permission to whatever he wants. I have already created a bucket and have generated an access key and a secret key for my IAM user.

All of the documentation on AWS dealing with permissions and policies is way too detailed and specific. I'm a newbie developer and just want to enable admin access to the S3 API for my heroku app.

Upvotes: 1

Views: 935

Answers (1)

Andrés Andrade
Andrés Andrade

Reputation: 2223

You can use the AWS Policy Generator

Here is a basic example of a policy which grants public access to get and put objects in a bucket:

    {
    "Version": "2012-10-17",
    "Id": "Policy1471524332942",
    "Statement": [
        {
            "Sid": "Stmt1471543432223",
            "Effect": "Allow",
            "Principal": "*",
            "Action": [
                "s3:GetObject",
                "s3:PutObject"
            ],
            "Resource": "arn:aws:s3:::bucketName/*"
        }
    ]
}

You will find more examples here.

You also need to configure CORS:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>https://yoursite.herokuapp.com</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

You will find more CORS examples here.

Hope it helps.

Upvotes: 2

Related Questions