Skip to content

Instantly share code, notes, and snippets.

@wata727
Created February 22, 2015 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wata727/b18381a75502a03094d4 to your computer and use it in GitHub Desktop.
Save wata727/b18381a75502a03094d4 to your computer and use it in GitHub Desktop.
自分のIPをSecurityGroupに登録する。22,80,8080,8090番を許可、無効化する
#!/bin/bash
# example : sh control-sg-myip.sh [action]
# action -> [auth,revoke]
if [ $# -ne 1 ]; then
echo "Error: Invalid argument count." 1>&2
exit 1
fi
sgid='sg-XXXXXXXX'
myip=`curl -s ifconfig.me`
action=$1
if [ ${action} = 'auth' ]; then
aws ec2 authorize-security-group-ingress --group-id ${sgid} --protocol tcp --port 22 --cidr ${myip}/32
aws ec2 authorize-security-group-ingress --group-id ${sgid} --protocol tcp --port 80 --cidr ${myip}/32
aws ec2 authorize-security-group-ingress --group-id ${sgid} --protocol tcp --port 8080 --cidr ${myip}/32
aws ec2 authorize-security-group-ingress --group-id ${sgid} --protocol tcp --port 8090 --cidr ${myip}/32
elif [ ${action} = 'revoke' ]; then
aws ec2 revoke-security-group-ingress --group-id ${sgid} --protocol tcp --port 22 --cidr ${myip}/32
aws ec2 revoke-security-group-ingress --group-id ${sgid} --protocol tcp --port 80 --cidr ${myip}/32
aws ec2 revoke-security-group-ingress --group-id ${sgid} --protocol tcp --port 8080 --cidr ${myip}/32
aws ec2 revoke-security-group-ingress --group-id ${sgid} --protocol tcp --port 8090 --cidr ${myip}/32
else
echo "Error: Invalid action." 1>&2
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment