Skip to content

Instantly share code, notes, and snippets.

@andrewp-as-is
Last active July 18, 2021 23:09
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 andrewp-as-is/a1b85e11c00630b995f9c51479681e08 to your computer and use it in GitHub Desktop.
Save andrewp-as-is/a1b85e11c00630b995f9c51479681e08 to your computer and use it in GitHub Desktop.
AWS IAM put-user-policy
#!/usr/bin/env bash
USER_NAME="test-user"
POLICY_NAME="policy-name"
aws iam create-user --user-name "$USER_NAME" 2> /dev/null
# https://docs.aws.amazon.com/cli/latest/reference/iam/put-user-policy.html
# IAM -> Users -> User -> Permissions -> Add inline policy
aws iam put-user-policy --user-name "$USER_NAME" --policy-name "$POLICY_NAME" --policy-document file://user-policy.json
# User Policy Examples:
# https://docs.aws.amazon.com/AmazonS3/latest/dev/example-policies-s3.html#iam-policy-ex0
{
"Version":"2012-10-17",
"Statement":[
{
"Effect":"Allow",
"Action":[
"s3:ListBucket",
"s3:GetBucketLocation"
],
"Resource":"arn:aws:s3:::BUCKET_NAME"
},
{
"Effect":"Allow",
"Action":[
"*"
],
"Resource":"arn:aws:s3:::BUCKET_NAME/*"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment