Skip to content

Instantly share code, notes, and snippets.

@bigdawggi
Last active July 24, 2020 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bigdawggi/de03d92589a33548e901d26cd9c55785 to your computer and use it in GitHub Desktop.
Save bigdawggi/de03d92589a33548e901d26cd9c55785 to your computer and use it in GitHub Desktop.
How to do restricted policies for programmatic (API) access to get/put objects into S3.

AWS being one of the most frustrating and difficult to use systems out there has to make everything difficult. This is something that has caused so much headache for me over the years, I'm starting to document it.

This README.md got me started, though didn't quite fit everything I needed.

Here's how you create Policies for a bucket

Assuming the following:

  1. You created a bucket named foo and that bucket has blocked all public access.
  2. You created a user named bar that was given API access (using keys and secrets).

You do the following:

  1. Add the following AS AN INLINE POLICY to the user -- this will not work when created as a policy on its own.
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListAllMyBuckets",
                "s3:PutObject",
                "s3:GetObject"
            ],
            "Resource": [
                "arn:aws:s3:::foo/*"
            ]
        }
    ]
}
  1. Add the following to the Bucket's policy
{
    "Version": "2012-10-17",
    "Id": "Policy1595548652552",
    "Statement": [
        {
            "Sid": "Stmt1595548649744",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::37122391:user/bar"
            },
            "Action": "s3:*",
            "Resource": "arn:aws:s3:::bar"
        }
    ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment