Skip to content

Instantly share code, notes, and snippets.

@nitrocode
Last active April 18, 2019 16:52
Show Gist options
  • Select an option

  • Save nitrocode/41a8d803223991a2e0fa9c2c49926c63 to your computer and use it in GitHub Desktop.

Select an option

Save nitrocode/41a8d803223991a2e0fa9c2c49926c63 to your computer and use it in GitHub Desktop.
S3 get bucket policy and make the json pretty
aws s3api get-bucket-policy --bucket vici-configs \
jq .Policy | \
sed 's/^"\(.*\)"$/\1/' | \
sed 's/\\//g' | \
jq
# jq .Policy will get the Policy key of the json
# 1st sed will remove the first and last quotes
# 2nd sed will remove backslashes
# last jq to prettify the json
@cfclrk

cfclrk commented Apr 18, 2019

Copy link
Copy Markdown

You can use jq -r instead of the first sed:

policy=$(aws s3api get-bucket-policy --bucket vici-configs)
echo $policy | jq -r '.Policy' | sed 's/\\//g' | jq

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment