Skip to content

Instantly share code, notes, and snippets.

@jkordish
Last active April 4, 2016 17:32
Show Gist options
  • Save jkordish/eb1df72433feb209eb3a to your computer and use it in GitHub Desktop.
Save jkordish/eb1df72433feb209eb3a to your computer and use it in GitHub Desktop.
Add resource to bucket policy
# Add an ARN to existing statement
policy=$(aws s3api get-bucket-policy --bucket <bucket> --query Policy --output text | jq '.Statement[0].Principal.AWS |= [.][]+ ["<resource arn>"]')
# push changes
aws s3api put-bucket-policy --bucket <bucket> --policy "${policy}"
###
# Merge statement lists from remote to your local (policy.json)
policy=$(aws s3api get-bucket-policy --bucket <bucket> --query Policy --output text | jq ".Statement |= .+ $(jq .Statement policy.json)")
# push changes
aws s3api put-bucket-policy --bucket <bucket> --policy "${policy}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment