Created
April 18, 2017 13:14
-
-
Save gordonmurray/c1215b372449cb3e2d11a30d407fa6ca 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
#!/usr/bin/env bash | |
# white list all public IPs from an AWS region in to a security group | |
security_group="sg-xxxxxx" | |
region="eu-west-1" | |
port="3306" | |
# list the public IPs from the instances in region | |
public_ips=`aws ec2 describe-instances --query "Reservations[*].Instances[*].PublicIpAddress" --output=text --region=${region} | xargs` | |
# Update the security group to allow the instance IPs on a given port number | |
for ip in ${public_ips} | |
do | |
echo "White listing IP: ${ip}.." | |
aws ec2 authorize-security-group-ingress --group-id ${security_group} --protocol tcp --port ${port} --cidr ${ip}/32 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment