Posted at

[AWS][EC2] インスタンスを停止~起動しても同じEIPを取得する方法

More than 5 years have passed since last update.

EC2のインスタンスを停止 -> 起動すると、せっかく日もづけた、EIPが外れてしまうので起動時に設定したEIPを自動的にバインドし直すshellを作成してみたメモです


# cat /etc/rc.local 

# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
# Update EIP
/usr/local/shell/ i-97068580 XXX.XXX.XXX.XXX > /tmp/bind_aws_eip.log 2>&1

# cat /usr/local/shell/



export AWS_SECRET_KEY='5isNk91VHB2WrabblsasGeU6m9sawYCgC5BWqb'
export JAVA_HOME="/usr"
export EC2_HOME="/opt/aws/apitools/ec2"

/opt/aws/bin/ec2-associate-address --region ${_AZ} -i ${_IID} ${_EIP}

/opt/aws/bin/ec2-describe-addresses --region ${_AZ}

exit 0