When you create an S3 bucket for a web app to use, you should create a specific IAM user to grant access to that bucket.
To do this, first create a user:
- Visit the IAM section of the AWS console
- Go to the “Users” section and click the “Create New Users” button
- Enter the user name(s) you want to create (e.g.
my-bucket-s3
for a bucket namedmy-bucket
) - When you’re shown the user credentials, save them somewhere safe, like our team 1Password vault
- When you return to the IAM users list, go to the newly created user and click on their “Permissions” tab. Click on the “Inline Policies” section and create a new policy
- Choose to create a “Custom Policy”
Name the policy “my-bucket-s3-access” (or something similarly descriptive) and paste the following into the “Policy Document” area (replacing
my-bucket
with your bucket’s name):{ "Statement": [ { "Effect": "Allow", "Action": "s3:ListAllMyBuckets", "Resource": "arn:aws:s3:::*" }, { "Effect": "Allow", "Action": "s3:*", "Resource": [ "arn:aws:s3:::my-bucket", "arn:aws:s3:::my-bucket/*" ] } ] }
Click “Apply Policy”
The access policy should now be active and your app should be able to access the bucket with the new IAM user’s credentials.