Skip to content

Instantly share code, notes, and snippets.

@oh-sky oh-sky/app-setup.sh
Created May 14, 2014

Embed
What would you like to do?
EC2のPublic IPをRDS Security GroupのCIDR/IPに、EC2のinstance-idをELBに自動登録
#!/bin/sh
do_start()
{
#このインスタンスのPublicIPアドレスをRDSのセキュリティグループに追加
PUBLICADDR=`curl http://169.254.169.254/latest/meta-data/public-ipv4 2> /dev/null`
aws rds authorize-db-security-group-ingress --db-security-group-name SECURITY-GROUP-NAME --cidrip "${PUBLICADDR}/32"
#このインスタンスをELB配下に置く
INSTANCEID=`curl http://169.254.169.254/latest/meta-data/instance-id 2> /dev/null`
aws elb register-instances-with-load-balancer --load-balancer-name LB-NAME --instances "${INSTANCEID}"
}
do_stop()
{
#このインスタンスのPublicIPアドレスをRDSのセキュリティグループから外す
PUBLICADDR=`curl http://169.254.169.254/latest/meta-data/public-ipv4 2> /dev/null`
aws rds revoke-db-security-group-ingress --db-security-group-name SECURITY-GROUP-NAME --cidrip "${PUBLICADDR}/32"
#このインスタンスをELBから外す
INSTANCEID=`curl http://169.254.169.254/latest/meta-data/instance-id 2> /dev/null`
aws elb deregister-instances-from-load-balancer --load-balancer-name LB-NAME --instances "${INSTANCEID}"
}
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
restart)
do_start
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2
exit 3
;;
esac
:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.