Skip to content

Instantly share code, notes, and snippets.

@gordonmurray
Created April 18, 2017 13:14
Show Gist options
  • Save gordonmurray/c1215b372449cb3e2d11a30d407fa6ca to your computer and use it in GitHub Desktop.
Save gordonmurray/c1215b372449cb3e2d11a30d407fa6ca to your computer and use it in GitHub Desktop.
#!/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