2014年1月3日

自動化管理 RDS 資料庫連線IP授權,使用 Amazon Command Line Interface

這份範例說明使用 AWS 的 CLI 指令工具,可以自動管理 RDS 連線的來源 IP 存取授權。考慮到出外或使用行動上網分享器時,需要自動偵測實際對外的 Public IP,所以這個範例也加上利用 curl + ifconfig.me 的說明,在分享器後方也能自動辨識出正確的 IP 位址。

安裝 AWS Command Line Interface (AWSCLI)

wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
sudo python ez_setup.py

wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
sudo python get-pip.py

pip install awscli

設定 AWS Credentials

$ aws configure
AWS Access Key ID [****************]:
AWS Secret Access Key [****************]:
Default region name [southeast]: ap-southeast-1
Default output format [None]:


增加IP授權

aws rds authorize-db-security-group-ingress --db-security-group-name GROUP --cidrip `curl ifconfig.me/ip`/32

解除IP授權

aws rds revoke-db-security-group-ingress --db-security-group-name GROUP --cidrip `curl ifconfig.me/ip`/32

沒有留言:

張貼留言

lyhcode by lyhcode
歡迎轉載,請務必註明出處!