cli53 を使って ホスト名を Route53 ( DNS ) に登録する bash スクリプト

#!/bin/bash

export AWS_ACCESS_KEY_ID='XXXXXXXXXX'
export AWS_SECRET_ACCESS_KEY='XXXXXXXXXXXXXXXXXXXX'

DOMAIN_NAME=`cli53 list | grep 'Name:' | sed 's/Name: //g' | sed "s/.\$//"`
HOST_NAME=`hostname`
PUBLIC_IPV4=`ec2-metadata | grep public-ipv4 | sed 's/public-ipv4: //g'`
LOCAL_IPV4=`ec2-metadata | grep local-ipv4 | sed 's/local-ipv4: //g'`
LOCAL_HOST_NAME=$HOST_NAME'.local'

echo $DOMAIN_NAME
echo $HOST_NAME
echo $PUBLIC_IPV4
echo $LOCAL_HOST_NAME
echo $LOCAL_IPV4

# バプリック(グローバル)IPを登録
/usr/bin/cli53 rrdelete $DOMAIN_NAME $HOST_NAME
/usr/bin/cli53 rrcreate $DOMAIN_NAME $HOST_NAME A $PUBLIC_IPV4 --ttl 360

# プライベート(ローカル)IPを登録 ホスト名.local.ドメイン名 形式
/usr/bin/cli53 rrdelete $DOMAIN_NAME $LOCAL_HOST_NAME
/usr/bin/cli53 rrcreate $DOMAIN_NAME $LOCAL_HOST_NAME A $LOCAL_IPV4 --ttl 360