Last active
June 4, 2021 05:31
-
-
Save shivam-tripathi/641c57a0655f7baa88e466936a2c5cd2 to your computer and use it in GitHub Desktop.
Bash script to white list your ip for a particular security group in AWS
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
export desc="shivam"; | |
export sg_id="SG_ID"; # update this | |
export AWS_PAGER=""; | |
# Revoke earlier white listed ip (compares it via desc) | |
aws ec2 describe-security-groups --group-ids $sg_id --output text | grep $desc | awk '{ print $2 }' | xargs -I {} aws ec2 revoke-security-group-ingress --group-id $sg_id --protocol tcp --port 0-65535 --cidr {}; | |
# Give permission to current public ip | |
wget -qO- ifconfig.me | xargs -I {} aws ec2 authorize-security-group-ingress --group-id $sg_id --ip-permissions IpProtocol=tcp,FromPort=0,ToPort=65535,IpRanges='[{CidrIp={}/32,Description="'$desc'"}]'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: