LoginSignup
1
0

More than 5 years have passed since last update.

EC2起動時にEIPのプールしているIP郡から使ってないIPを選択して割り当てるワンライナー

Posted at

内容

インスタンス立てるときに特定のEIPの中からどれかをつけて立ってほしかったから作ったワンライナー

前提

  • EC2からEIP触れる権限があたってること。
  • 事前にIP確保しておくこと
  • 確保したIPにタグをつけておくこと(タグでフィルタします)

コマンド

変数
export REGION=ap-northeast-1
export TAG_NAME="hogehoge-tag"
ワンライナー
aws ec2 associate-address \
    --region ${REGION} \
    --instance-id $(curl http://169.254.169.254/latest/meta-data/instance-id) \
    --allocation-id $(aws ec2 describe-addresses \
                        --filters "Name=tag-key,Values=Name" \
                                  "Name=tag-value,Values=${TAG_NAME}" \
                        --query "Addresses[?AssociationId==\`null\`].AllocationId" \
                        --region ${REGION} \
                        --output text | cut -f 1 )
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0