同じリージョンの AWS アカウント間で Elastic IP アドレスを一括移管するにはどうすればよいですか?
同じ AWS リージョンの AWS アカウント間で複数の Elastic IP アドレスを移管したいと考えています。
簡単な説明
Elastic IP アドレスを移管する際は、移管元アカウントと移管先アカウントの間で 2 段階のハンドシェイクが行われます。移管元アカウントは、標準の AWS アカウントまたは AWS Organizations アカウントのいずれかです。移管元アカウントが移行を開始すると、移管先アカウントは 7 日間で受け入れる必要があります。そうしない場合、Elastic IP アドレスは元の所有者に戻ります。
AWS は、移管先アカウントに対して保留中の Elastic IP アドレスの移管リクエストについて通知しません。所定の時間内にスムーズに移管できるよう、ソースアカウントの所有者が移管先アカウントの所有者にこのリクエストを伝える必要があります。
複数の Elastic IP アドレスを一度に移管するには、Linux の bash スクリプトを使用します。
注: アカウント間で単一の Elastic IP アドレスを移管するには、「同じリージョン内の AWS アカウント間で Elastic IP アドレスを移管する方法はありますか?」を参照してください。
解決方法
注: AWS コマンドラインインターフェイス (AWS CLI) コマンドの実行中にエラーが発生した場合は、最新バージョンの AWS CLI を使用していることを確認してください。
IP アドレスを移管する (移管元アカウント所有者)
1. 移管元アカウントの AWS CLI の認証情報を設定したことを確認します。また、ec2:DescribeAddresses API と ec2:EnableAddressTransfer API の呼び出しを許可する AWS Identity and Access Management (IAM) の権限があることを確認します。
2. テキストファイルに Elastic IP アドレスを 1 行に 1 つずつ追加します。次の bash スクリプトの例では、このテキストファイルの名前は eips.txt です。
3. 次の例のような EIPTransfer.sh という名前の bash スクリプトを作成します。
#! /bin/bash ARRAY=() while read line do ARRAY+=($line) done < $1 now_start="$(date)" echo "Starting the loop to enable transfer of the provided EIPs in Region: $2 from AWS account: $3 to AWS account: $4 at $now_start" >> EIPTransfer-results-"`date +"%d-%m-%Y"`".txt for i in "${ARRAY[@]}" do echo "Trying to get the AllocationId for ${i}" >> EIPTransfer-results-"`date +"%d-%m-%Y"`".txt EIPAlloc=`aws ec2 describe-addresses --filters "Name=public-ip,Values=${i}" --query "Addresses[].AllocationId" --region $2 --output text` if [[ "$EIPAlloc" == *"eipalloc"* ]]; then echo "Trying to enable transfer for ${i} with allocation-id $EIPAlloc" >> EIPTransfer-results-"`date +"%d-%m-%Y"`".txt aws ec2 enable-address-transfer --allocation-id ${EIPAlloc} --transfer-account-id $4 --region $2 --output text >> EIPTransfer-results-"`date +"%d-%m-%Y"`".txt 2>&1 else echo "No allocation-id found for EIP ${i}" >> EIPTransfer-results-"`date +"%d-%m-%Y"`".txt fi done now_end="$(date)" echo "All done! Exiting the script at $now_end!" >> EIPTransfer-results-"`date +"%d-%m-%Y"`".txt ## usage sh EIPTransfer.sh eips.txt xx-region-y srcaccount dstaccount
4. このスクリプトを実行するには、次のコマンドを実行します。
sh EIPTransfer.sh eips.txt xx-region-y srcaccount dstaccount
5. EIPTransfer ログにエラーがないか確認してください。ログの名前は EIPTransfer-results-DATE.txt です。
注: このファイル名の DATE はスクリプトを実行した日付です。
移管を承認する (アカウント所有者の移管)
1. 移管アカウントの AWS CLI の認証情報を設定したことを確認します。また、ec2:AcceptAddressTransfer API の呼び出しを許可する IAM 権限を持っていることも確認します。
2. テキストファイルに Elastic IP アドレスを 1 行に 1 つずつ追加します。次の bash スクリプトの例では、このテキストファイルの名前は eips.txt です。
3. 次の例のような EIPAccept.sh という名前の bash スクリプトを作成します。
#! /bin/bash ARRAY=() while read line do ARRAY+=($line) done < $1 now_start="$(date)" echo "Starting the loop to accept transfer of the provided EIPs in Region: $2 from AWS account: $3 to AWS account: $4 at $now_start" >> EIPAccept-results-"`date +"%d-%m-%Y"`".txt for i in "${ARRAY[@]}" do echo "Trying to accept the EIP transfer for ${i} from account $3" >> EIPAccept-results-"`date +"%d-%m-%Y"`".txt aws ec2 accept-address-transfer --address ${i} --region $2 --output text >> EIPAccept-results-"`date +"%d-%m-%Y"`".txt 2>&1 done now_end="$(date)" echo "All done! Exiting the script at $now_end!" >> EIPAccept-results-"`date +"%d-%m-%Y"`".txt ## usage sh EIPAccept.sh eips.txt xx-region-y srcaccount dstaccount
4. このスクリプトを実行するには、次のコマンドを実行します。
sh EIPAccept.sh eips.txt xx-region-y srcaccount dstaccount
5. EIPAccept ログにエラーがないか確認してください。このログの名前は EIPAccept-results-DATE.txt です。
注: このファイル名の DATE はスクリプトを実行した日付です。
- 言語
- 日本語
