AWS CLI コマンドを使用して Lightsail インスタンスの静的 IP アドレスを管理する方法を教えてください。

所要時間2分
0

静的 IP アドレスを Amazon Lightsail インスタンスからデタッチして、新しい Lightsail インスタンスにアタッチしようと思います。これを AWS Command Line Interface (AWS CLI) で行う方法を教えてください。

簡単な説明

Amazon Lightsail AWS CLI コマンドの一覧については、AWS CLI コマンドリファレンスおよび Amazon Lightsail API リファレンスを参照してください。

重要: AWS CLI コマンドを使用するときは、次の点に注意してください。

macOS の場合:

タイムスタンプから小数点を削除し、小数点の右側にある任意の数字を削除して、次のコマンドを実行します。

# date -r 1602175741 -u
Thu Oct  8 16:49:01 UTC 2020

Linux の場合:

次のコマンドを実行します。

# date -d @1602175741.603 -u
Thu Oct  8 16:49:01 UTC 2020

Windows の場合:

epochconverter.com などのコンバーターを使用して、タイムスタンプを変換します。

解決方法

既存の Lightsail インスタンスから静的 IP アドレスをデタッチする

detach-static-ip コマンドを実行して、インスタンスから静的 IP アドレスをデタッチします。次の例では、eu-west-1 リージョンのインスタンスから静的 IP アドレスをデタッチします。--static-ip-name および --region を要求の値で置き換えます。

# aws lightsail detach-static-ip --static-ip-name StaticIpForTestLightsailInstance1 --region eu-west-1
{
    "operations": [
        {
            "id": "c86e552e-c21a-4cdf-aa68-05fb20574e8b",
            "resourceName": "StaticIpForTestLightsailInstance1",
            "resourceType": "StaticIp",
            "createdAt": 1602182597.168,
            "location": {
                "availabilityZone": "all",
                "regionName": "eu-west-1"
            },
            "isTerminal": true,
            "operationDetails": "TestLightsailInstance1",
            "operationType": "DetachStaticIp",
            "status": "Succeeded",
            "statusChangedAt": 1602182597.168
        },
        {
            "id": "4b9dcaa7-be3a-4dfd-8ac0-32f0238c0833",
            "resourceName": "TestLightsailInstance1",
            "resourceType": "Instance",
            "createdAt": 1602182597.17,
            "location": {
                "availabilityZone": "eu-west-1a",
                "regionName": "eu-west-1"
            },
            "isTerminal": true,
            "operationDetails": "StaticIpForTestLightsailInstance1",
            "operationType": "DetachStaticIp",
            "status": "Succeeded",
            "statusChangedAt": 1602182597.17
        }
    ]
}

静的 IP アドレスを新しい Lightsail インスタンスにアタッチする

1.    attach-static-ip コマンドを実行して、静的 IP アドレスをバックアップから新しいインスタンスにアタッチします。--static-ip-name--instance-name、および --region を要求の値で置き換えます。

# aws lightsail attach-static-ip --static-ip-name StaticIpForTestLightsailInstance1 --instance-name RestoredTestLightsailInstance1-New  --region eu-west-1
{
    "operations": [
        {
            "id": "192c4917-c332-49c8-88ab-60484a42c98f",
            "resourceName": "StaticIpForTestLightsailInstance1",
            "resourceType": "StaticIp",
            "createdAt": 1602182686.46,
            "location": {
                "availabilityZone": "all",
                "regionName": "eu-west-1"
            },
            "isTerminal": true,
            "operationDetails": "RestoredTestLightsailInstance1-New",
            "operationType": "AttachStaticIp",
            "status": "Succeeded",
            "statusChangedAt": 1602182686.46
        },
        {
            "id": "fb93c012-e3a2-4908-8746-01a4ae018440",
            "resourceName": "RestoredTestLightsailInstance1-New",
            "resourceType": "Instance",
            "createdAt": 1602182686.463,
            "location": {
                "availabilityZone": "eu-west-1a",
                "regionName": "eu-west-1"
            },
            "isTerminal": true,
            "operationDetails": "StaticIpForTestLightsailInstance1",
            "operationType": "AttachStaticIp",
            "status": "Succeeded",
            "statusChangedAt": 1602182686.463
        }
    ]
}

2.    get-instances コマンドを実行して、静的 IP アドレスがインスタンスに割り当てられていることを確認します。

# aws lightsail get-instances --region eu-west-1 --query 'instances[].{name:name,createdAt:createdAt,blueprintId:blueprintId,bundleid:bundleId,blueprintName:blueprintName,publicIpAddress:publicIpAddress,InstanceID:supportCode}' --output table
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
|                                                                            GetInstances                                                                            |
+----------------------------------+------------------+----------------+------------+-----------------+------------------------------------------+-------------------+
|            InstanceID            |   blueprintId    | blueprintName  | bundleid   |    createdAt    |                  name                    |  publicIpAddress  |
+----------------------------------+------------------+----------------+------------+-----------------+------------------------------------------+-------------------+
|  11178xxxxxxx/i-09f6xxxx|  wordpress       |  WordPress     |  large_2_0 |  1602182374.625 |  RestoredTestLightsailInstance1-New      |  52.210.xx.xx     |
+----------------------------------+------------------+----------------+------------+-----------------+------------------------------------------+-------------------+

関連情報

AWS CLI コマンドを使用して Lightsail インスタンスを管理する方法を教えてください。

AWS CLI コマンドを使用して Lightsail インスタンスのスナップショットを管理し、バックアップを作成するにはどうすればよいですか?

Amazon Lightsail のインスタンスやディスクの自動スナップショットを有効または無効にします。

Lightsail ドキュメント

AWS公式
AWS公式更新しました 3年前
コメントはありません

関連するコンテンツ