Skip to content

Instantly share code, notes, and snippets.

@shuson
Created July 5, 2024 04:04
Show Gist options
  • Save shuson/c34bcaeb324fd07d65a7a4e7196ff1d5 to your computer and use it in GitHub Desktop.
Save shuson/c34bcaeb324fd07d65a7a4e7196ff1d5 to your computer and use it in GitHub Desktop.
aws cloudshell batch add IP to security group
GROUP_ID="sg-xxx"
# Define your list of IP addresses
IP_LIST=("192.0.2.0/24" "198.51.100.0/24" "203.0.113.0/24")
# Define the list of ports
PORT_LIST=(22 80 443)
# Add each IP address to the security group for each port
for IP in "${IP_LIST[@]}"; do
for PORT in "${PORT_LIST[@]}"; do
aws ec2 authorize-security-group-ingress --group-id $GROUP_ID --protocol tcp --port $PORT --cidr $IP
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment