Created
May 14, 2014 14:13
-
-
Save oh-sky/f115e0a640a7762564f9 to your computer and use it in GitHub Desktop.
EC2のPublic IPをRDS Security GroupのCIDR/IPに、EC2のinstance-idをELBに自動登録
This file contains hidden or 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/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