Created
July 14, 2017 18:38
-
-
Save cynicXer/7353eed94c116901e3af677090d90b8d to your computer and use it in GitHub Desktop.
AWS Modify Default Security Group Bash Script
This file contains hidden or 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
groupname=default | |
regions=$(aws ec2 describe-regions \ | |
--output text \ | |
--query 'Regions[*].RegionName') | |
for region in $regions; do | |
default_group_id=$(aws ec2 describe-security-groups --region $region --group-name $groupname \ | |
| jq -r '.SecurityGroups[] | .GroupId') | |
echo "Revoking any/any rule from default groupID: $default_group_id in region: $region" | |
aws ec2 revoke-security-group-ingress \ | |
--region "$region" \ | |
--group-name "$groupname" \ | |
--proto "all" \ | |
--port "all" \ | |
--source-group "$default_group_id" | |
echo "Adding rules to $groupname in $region..." | |
aws ec2 authorize-security-group-ingress \ | |
--region "$region" \ | |
--group-name "$groupname" \ | |
--protocol "tcp" \ | |
--port "22" \ | |
--cidr "0.0.0.0/0" | |
aws ec2 authorize-security-group-ingress \ | |
--region "$region" \ | |
--group-name "$groupname" \ | |
--protocol "tcp" \ | |
--port "80" \ | |
--cidr "0.0.0.0/0" | |
aws ec2 authorize-security-group-ingress \ | |
--region "$region" \ | |
--group-name "$groupname" \ | |
--protocol "tcp" \ | |
--port "443" \ | |
--cidr "0.0.0.0/0" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment