Last active
September 11, 2019 14:47
-
-
Save abhigets/a12bc533efac502e82b9219858bdbda8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#get the policy from aws and store it in variable | |
BUCKET_NAME="your bucket name" | |
S3_OLD_POLICY=$(aws s3api get-bucket-policy --bucket ${BUCKET_NAME} --query Policy --output text) | |
echo $S3_OLD_POLICY | |
echo "---------------" | |
#get the ip of my host | |
MY_IP=$(curl ipecho.net/plain;) | |
echo $MY_IP | |
echo "---------------" | |
#append my ip to | |
S3_NEW_POLICY=$(echo $S3_OLD_POLICY | sed 's;]}}}]};,\"'$MY_IP'\"]}}}]};g') | |
echo $S3_NEW_POLICY | |
echo "---------------" | |
#apply new policy to s3 bucket | |
aws s3api put-bucket-policy --bucket ${BUCKET_NAME} --policy ${S3_NEW_POLICY} | |
#if update and restore are different script then one can write the old policy to a file to retrive to later while restoring | |
#echo $S3_OLD_POLICY > "S3_OLD_POLICY.json" | |
#Do your task | |
#like i ran e2e test | |
#restoring the old policy | |
#restore the policy if it was initially stored in a file | |
#S3_OLD_POLICY=$(<"S3_OLD_POLICY.json") | |
aws s3api put-bucket-policy --bucket ${BUCKET_NAME} --policy ${S3_OLD_POLICY} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment