後始末5.3. Lightsailインスタンスからの静的IPアドレスのデタッチ (handson-cli-lightsail-instance)¶
作業の目的 [why]¶
Lightsailインスタンス"handson-cli-lightsail-instance"からLightsail静的IPアドレス"handson-cli-lightsail-static_ip"をデタッチします。
完了条件/事前条件 [設計者用情報]
完了条件 [after]
主処理は、以下を満たしたときに成功したものとします。
- 完了条件1
Lightsailインスタンス"handson-cli-lightsail-instance"にLightsail静的IPアドレス"handson-cli-lightsail-static_ip"がアタッチされていない。
事前条件 [before]
主処理の実施は、以下の状態であることを前提とします。
- 事前条件1
Lightsailインスタンス"handson-cli-lightsail-instance"が存在する。
- 事前条件2
Lightsail静的IPアドレス"handson-cli-lightsail-static_ip"が存在する。
- 事前条件3
Lightsailインスタンス"handson-cli-lightsail-instance"にLightsail静的IPアドレス"handson-cli-lightsail-static_ip"がアタッチされている。
作業対象 [what]¶
Lightsailサービス
標準時間(合計)¶
8分
パラメータ設定¶
- パラメータ設定の標準時間
2分
作業に必要なモノ・情報 [resource]¶
作業開始には、以下が全て揃っていることが必要です。
リソース1: Lightsailインスタンス名
Lightsail静的IPアドレスからデタッチするLightsailインスタンスの名称です。
今回は"handson-cli-lightsail-instance"とします。
リソース2: Lightsail静的IPアドレス名
LightSailインスタンスからデタッチするLightsail静的IPアドレスの名称です。
今回は"handson-cli-lightsail-static_ip"とします。
パラメータの指定¶
作業に必要なパラメータを変数に格納をします。
0.1. Lightsailインスタンス名の指定¶
Lightsailインスタンス名を指定します。
変数の設定:
LIGHTSAIL_INSTANCE_NAME="handson-cli-lightsail-instance"
0.2. Lightsail静的IPアドレス名の指定¶
静的IPアドレス名を指定します。
変数の設定:
LIGHTSAIL_STATIC_IP_NAME="handson-cli-lightsail-static_ip"
パラメータの保存¶
設定されている変数の保存先となるファイル名を指定します。
変数の設定:
DIR_PARAMETER="${HOME}/tmp/parameter-handson-cli-lightsail" FILE_PARAMETER="${DIR_PARAMETER}/$(date +%Y-%m-%d)-lightsail-static_ip_detach-update.env" \ && echo ${FILE_PARAMETER}
結果(例):
${HOME}/tmp/parameter-handson-cli-lightsail/2020-02-10-lightsail-static_ip_detach-update.env
各変数に正しいパラメータ値が格納されていることを確認しながら保存します。
変数の確認:
cat << EOF > ${FILE_PARAMETER} # 0.0. AWS_DEFAULT_REGION:"ap-northeast-1" AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" # 0.1. LIGHTSAIL_INSTANCE_NAME:"handson-cli-lightsail-instance" LIGHTSAIL_INSTANCE_NAME="${LIGHTSAIL_INSTANCE_NAME}" # 0.2. LIGHTSAIL_STATIC_IP_NAME:"handson-cli-lightsail-static_ip" LIGHTSAIL_STATIC_IP_NAME="${LIGHTSAIL_STATIC_IP_NAME}" EOF cat ${FILE_PARAMETER}
下段の変数が入っていない、もしくは上段と同等の値が入っていない場合は、それぞれの手順番号に戻って変数の設定を行います。
タスクの実施¶
- タスク標準時間
6分
1. 前処理¶
処理対象の状態確認¶
主処理の実施は、以下の状態であることを前提とします。
前提と異なることが判明した場合、直ちに処理を中止します。
事前条件1: Lightsailインスタンス"handson-cli-lightsail-instance"が存在する。
「Lightsailインスタンス"handson-cli-lightsail-instance"が存在する。」ことを確認します。
コマンド:
aws lightsail get-instances \ --query "instances[?name == \`${LIGHTSAIL_INSTANCE_NAME}\`].name" \ --output text
結果(例):
handson-cli-lightsail-instance
事前条件2: Lightsail静的IPアドレス"handson-cli-lightsail-static_ip"が存在する。
「Lightsail静的IPアドレス"handson-cli-lightsail-static_ip"が存在する。」ことを確認します。
コマンド:
aws lightsail get-static-ips \ --query "staticIps[?name == \`${LIGHTSAIL_STATIC_IP_NAME}\`].name" \ --output text
結果(例):
handson-cli-lightsail-static_ip
事前条件3: Lightsailインスタンス"handson-cli-lightsail-instance"にLightsail静的IPアドレス"handson-cli-lightsail-static_ip"がアタッチされている。
「Lightsailインスタンス"handson-cli-lightsail-instance"にLightsail静的IPアドレス"handson-cli-lightsail-static_ip"がアタッチされている。」ことを確認します。
コマンド:
aws lightsail get-static-ips \ --query "staticIps[?attachedTo == \`${LIGHTSAIL_INSTANCE_NAME}\`].name" \ --output text
結果(例):
handson-cli-lightsail-static_ip
2. 主処理¶
Lightsailインスタンスからの静的IPアドレスのデタッチ¶
変数の確認:
cat << ETX # LIGHTSAIL_STATIC_IP_NAME:"handson-cli-lightsail-static_ip" LIGHTSAIL_STATIC_IP_NAME="${LIGHTSAIL_STATIC_IP_NAME}" ETX
コマンド:
aws lightsail detach-static-ip \ --static-ip-name ${LIGHTSAIL_STATIC_IP_NAME}
結果(例):
{ "operations": [ { "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "resourceName": "handson-cli-lightsail-static_ip", "resourceType": "StaticIp", "createdAt": 1234567890.123, "location": { "availabilityZone": "all", "regionName": "ap-northeast-1" }, "isTerminal": true, "operationDetails": "handson-cli-lightsail-instance", "operationType": "DetachStaticIp", "status": "Succeeded", "statusChangedAt": 1234567890.123 }, { "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "resourceName": "handson-cli-lightsail-instance", "resourceType": "Instance", "createdAt": 1234567890.12, "location": { "availabilityZone": "ap-northeast-1a", "regionName": "ap-northeast-1" }, "isTerminal": true, "operationDetails": "handson-cli-lightsail-static_ip", "operationType": "DetachStaticIp", "status": "Succeeded", "statusChangedAt": 1234567890.12 } ] }
3. 後処理¶
完了条件の確認¶
主処理は、以下を満たしたときに成功したものとします。
完了条件1: Lightsailインスタンス"handson-cli-lightsail-instance"にLightsail静的IPアドレス"handson-cli-lightsail-static_ip"がアタッチされていない。
「Lightsailインスタンス"handson-cli-lightsail-instance"にLightsail静的IPアドレス"handson-cli-lightsail-static_ip"がアタッチされていない。」ことを確認します。
コマンド:
aws lightsail get-static-ips \ --query "staticIps[?attachedTo == \`${LIGHTSAIL_INSTANCE_NAME}\`].name" \ --output text
結果(例):
(出力なし)