Created
February 22, 2015 10:28
-
-
Save wata727/b18381a75502a03094d4 to your computer and use it in GitHub Desktop.
自分のIPをSecurityGroupに登録する。22,80,8080,8090番を許可、無効化する
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
#!/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