Amazon Lightsail インスタンスのスケールアップ手順を試してみた

2017.01.19

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

こんにちは、菊池です。

AWS re:Invent 2016で発表されたAmazon Lightsailで、インスタンスのスケールアップを試してみました。

手順

EC2インスタンスのスケールアップではインスタンスの停止 -> インスタンスタイプの変更 -> 起動 の手順で簡単にスケールアップが可能です。一方、Lightsailでは手順が異なり、現時点で以下の点に注意が必要です。

  • 一度作成/起動したインスタンスのスペック変更は不可能
  • コンソールからの操作だけでは不可能で、AWS CLIによる操作が必要

まず、一度作成したのインスタンスのスペック変更はできませんので、以下のような手順を踏む必要があります。

  1. 対象インスタンスのSnapshotを作成
  2. AWS CLIを使ってSnapshotからBundle-IDを指定してインスタンスを作成
  3. DNSレコードまたはStatic IPを変更し、新しく作成したインスタンスにユーザのアクセス先を変更
  4. 元のインスタンスを削除

ls-scaleup

 

やってみた

実際に、AWS CLIから以下の作業を実施してみました。

  • Snapshot作成
  • スナップショットからインスタンス作成
  • 元のインスタンスを削除

まずは起動しているインスタンスをget-instancesで確認します。

$ aws lightsail --region us-east-1 get-instances
{
    "instances": [
        {
            "username": "bitnami",
            "isStaticIp": false,
            "networking": {
                "monthlyTransfer": {
                    "gbPerMonthAllocated": 1000
                },
                "ports": [
                    {
                        "protocol": "tcp",
                        "accessType": "public",
                        "commonName": "",
                        "accessFrom": "Anywhere (0.0.0.0/0)",
                        "fromPort": 80,
                        "accessDirection": "inbound",
                        "toPort": 80
                    },
                    {
                        "protocol": "tcp",
                        "accessType": "public",
                        "commonName": "",
                        "accessFrom": "Anywhere (0.0.0.0/0)",
                        "fromPort": 22,
                        "accessDirection": "inbound",
                        "toPort": 22
                    },
                    {
                        "protocol": "tcp",
                        "accessType": "public",
                        "commonName": "",
                        "accessFrom": "Anywhere (0.0.0.0/0)",
                        "fromPort": 443,
                        "accessDirection": "inbound",
                        "toPort": 443
                    }
                ]
            },
            "name": "WordPress-1",
            "resourceType": "Instance",
            "supportCode": "015515485450/i-xxxxxxxxxxxxxxxxx",
            "blueprintName": "WordPress",
            "hardware": {
                "cpuCount": 1,
                "ramSizeInGb": 0.5
            },
            "privateIpAddress": "172.26.8.26",
            "state": {
                "code": 16,
                "name": "running"
            },
            "arn": "arn:aws:lightsail:us-east-1:xxxxxxxxxxxx:Instance/b9e61e46-50ff-4fb5-bef6-8efc0ce5b8cf",
            "publicIpAddress": "52.206.xxx.xxx",
            "blueprintId": "wordpress_4_6_1",
            "bundleId": "nano_1_0",
            "sshKeyName": "LightsailDefaultKeyPair",
            "createdAt": 1484776375.816,
            "location": {
                "availabilityZone": "us-east-1a",
                "regionName": "us-east-1"
            }
        }
    ]
}

"name": "WordPress-1"というインスタンスが起動していますので、create-instance-snapshotでSnapshotを作成します。

$ aws lightsail --region us-east-1 create-instance-snapshot \
    --instance-snapshot-name "WordPress-1-snapshot" \
    --instance-name "WordPress-1"
{
    "operations": [
        {
            "status": "Started",
            "resourceType": "InstanceSnapshot",
            "isTerminal": false,
            "operationDetails": "WordPress-1",
            "statusChangedAt": 1484778032.035,
            "location": {
                "availabilityZone": "all",
                "regionName": "us-east-1"
            },
            "operationType": "CreateInstanceSnapshot",
            "resourceName": "WordPress-1-snapshot",
            "id": "85bfae0a-b585-40f5-a061-57340eed07be",
            "createdAt": 1484778032.035
        },
        {
            "status": "Started",
            "resourceType": "Instance",
            "isTerminal": false,
            "operationDetails": "WordPress-1-snapshot",
            "statusChangedAt": 1484778032.035,
            "location": {
                "availabilityZone": "us-east-1a",
                "regionName": "us-east-1"
            },
            "operationType": "CreateInstanceSnapshot",
            "resourceName": "WordPress-1",
            "id": "3b395b8c-98e1-4eb4-95d2-2ef742bc116e",
            "createdAt": 1484778032.035
        }
    ]
}

Snapshot作成が開始されましたので、利用可能になるまで待ちます。Snapshotのステータスはget-instance-snapshotsで確認できます。

$ aws lightsail --region us-east-1 get-instance-snapshots
{
    "instanceSnapshots": [
        {
            "fromInstanceName": "WordPress-1",
            "name": "WordPress-1-snapshot",
            "sizeInGb": 20,
            "resourceType": "InstanceSnapshot",
            "supportCode": "015515485450/ami-cfe50dd9",
            "fromInstanceArn": "arn:aws:lightsail:us-east-1:xxxxxxxxxxxx:Instance/b9e61e46-50ff-4fb5-bef6-8efc0ce5b8cf",
            "state": "pending",
            "arn": "arn:aws:lightsail:us-east-1:xxxxxxxxxxxx:InstanceSnapshot/13730bd7-69eb-44a0-b79c-5f2f3dc0b39a",
            "fromBundleId": "nano_1_0",
            "fromBlueprintId": "wordpress_4_6_1",
            "createdAt": 1484778032.035,
            "location": {
                "availabilityZone": "all",
                "regionName": "us-east-1"
            }
        }
    ]
}

"state": "pending"となっているのが、"state": "available"となれば利用可能です。

$ aws lightsail --region us-east-1 get-instance-snapshots
{
    "instanceSnapshots": [
        {
            "fromInstanceName": "WordPress-1",
            "name": "WordPress-1-snapshot",
            "sizeInGb": 20,
            "resourceType": "InstanceSnapshot",
            "supportCode": "015515485450/ami-cfe50dd9",
            "fromInstanceArn": "arn:aws:lightsail:us-east-1:xxxxxxxxxxxx:Instance/b9e61e46-50ff-4fb5-bef6-8efc0ce5b8cf",
            "state": "available",
            "arn": "arn:aws:lightsail:us-east-1:xxxxxxxxxxxx:InstanceSnapshot/13730bd7-69eb-44a0-b79c-5f2f3dc0b39a",
            "fromBundleId": "nano_1_0",
            "fromBlueprintId": "wordpress_4_6_1",
            "createdAt": 1484778032.035,
            "location": {
                "availabilityZone": "all",
                "regionName": "us-east-1"
            }
        }
    ]
}

利用可能になりましたので、create-instances-from-snapshotでSnapshotからインスタンスを作成します。ここで、--bundle-idに指定するスペックで、新しいインスタンスが起動します。今回は、元がNano (t2.nano) なので、Micro (t2.micro) を指定してみます。選択可能なスペックは、get-bundlesで取得できます。

 

$ aws lightsail --region us-east-1 create-instances-from-snapshot \
    --instance-names "WordPress-2" \
    --availability-zone "us-east-1a" \
    --instance-snapshot-name "WordPress-1-snapshot" \
    --bundle-id "micro_1_0"
{
    "operations": [
        {
            "status": "Started",
            "resourceType": "Instance",
            "isTerminal": false,
            "statusChangedAt": 1484778376.64,
            "location": {
                "availabilityZone": "us-east-1a",
                "regionName": "us-east-1"
            },
            "operationType": "CreateInstance",
            "resourceName": "WordPress-2",
            "id": "8dac1f7d-bb20-4e8f-baad-06f0f57d757e",
            "createdAt": 1484778375.136
        }
    ]
}

インスタンスが起動できたか、再度get-instancesで確認してみます。

$ aws lightsail --region us-east-1 get-instances
{
    "instances": [
        {
            "username": "bitnami",
            "isStaticIp": false,
            "networking": {
                "monthlyTransfer": {
                    "gbPerMonthAllocated": 1000
                },
                "ports": [
                    {
                        "protocol": "tcp",
                        "accessType": "public",
                        "commonName": "",
                        "accessFrom": "Anywhere (0.0.0.0/0)",
                        "fromPort": 80,
                        "accessDirection": "inbound",
                        "toPort": 80
                    },
                    {
                        "protocol": "tcp",
                        "accessType": "public",
                        "commonName": "",
                        "accessFrom": "Anywhere (0.0.0.0/0)",
                        "fromPort": 22,
                        "accessDirection": "inbound",
                        "toPort": 22
                    },
                    {
                        "protocol": "tcp",
                        "accessType": "public",
                        "commonName": "",
                        "accessFrom": "Anywhere (0.0.0.0/0)",
                        "fromPort": 443,
                        "accessDirection": "inbound",
                        "toPort": 443
                    }
                ]
            },
            "name": "WordPress-1",
            "resourceType": "Instance",
            "supportCode": "015515485450/i-xxxxxxxxxxxxxxxxx",
            "blueprintName": "WordPress",
            "hardware": {
                "cpuCount": 1,
                "ramSizeInGb": 0.5
            },
            "privateIpAddress": "172.26.8.26",
            "state": {
                "code": 16,
                "name": "running"
            },
            "arn": "arn:aws:lightsail:us-east-1:xxxxxxxxxxxx:Instance/b9e61e46-50ff-4fb5-bef6-8efc0ce5b8cf",
            "publicIpAddress": "52.206.xxx.xxx",
            "blueprintId": "wordpress_4_6_1",
            "bundleId": "nano_1_0",
            "sshKeyName": "LightsailDefaultKeyPair",
            "createdAt": 1484776375.816,
            "location": {
                "availabilityZone": "us-east-1a",
                "regionName": "us-east-1"
            }
        },
        {
            "username": "bitnami",
            "isStaticIp": false,
            "networking": {
                "monthlyTransfer": {
                    "gbPerMonthAllocated": 2000
                },
                "ports": [
                    {
                        "protocol": "tcp",
                        "accessType": "public",
                        "commonName": "",
                        "accessFrom": "Anywhere (0.0.0.0/0)",
                        "fromPort": 80,
                        "accessDirection": "inbound",
                        "toPort": 80
                    },
                    {
                        "protocol": "tcp",
                        "accessType": "public",
                        "commonName": "",
                        "accessFrom": "Anywhere (0.0.0.0/0)",
                        "fromPort": 22,
                        "accessDirection": "inbound",
                        "toPort": 22
                    },
                    {
                        "protocol": "tcp",
                        "accessType": "public",
                        "commonName": "",
                        "accessFrom": "Anywhere (0.0.0.0/0)",
                        "fromPort": 443,
                        "accessDirection": "inbound",
                        "toPort": 443
                    }
                ]
            },
            "name": "WordPress-2",
            "resourceType": "Instance",
            "supportCode": "015515485450/i-xxxxxxxxxxxxxxxxx",
            "blueprintName": "WordPress",
            "hardware": {
                "cpuCount": 1,
                "ramSizeInGb": 1.0
            },
            "privateIpAddress": "172.26.9.209",
            "state": {
                "code": 16,
                "name": "running"
            },
            "arn": "arn:aws:lightsail:us-east-1:xxxxxxxxxxxx:Instance/d61f5bf5-760b-43ac-b106-6548e97dc736",
            "publicIpAddress": "54.152.xxx.xxx",
            "blueprintId": "wordpress_4_6_1",
            "bundleId": "micro_1_0",
            "sshKeyName": "LightsailDefaultKeyPair",
            "createdAt": 1484778375.136,
            "location": {
                "availabilityZone": "us-east-1a",
                "regionName": "us-east-1"
            }
        }
    ]
}

"name": "WordPress-2"のインスタンスが起動しています。これで、スケールアップしたインスタンスができましたので、あとはDNSレコードやStatic IPを変更してアクセスを切替てあげましょう。

最後に、元のインスタンス"name": "WordPress-1"delete-instanceで削除します。

$ aws lightsail --region us-east-1 delete-instance --instance-name "WordPress-1"
{
    "operations": [
        {
            "status": "Succeeded",
            "resourceType": "Instance",
            "isTerminal": true,
            "statusChangedAt": 1484778487.919,
            "location": {
                "availabilityZone": "us-east-1a",
                "regionName": "us-east-1"
            },
            "operationType": "DeleteInstance",
            "resourceName": "WordPress-1",
            "id": "a83fd1c3-11e1-43e3-a605-5cb13a76f48a",
            "createdAt": 1484778487.919
        }
    ]
}

削除できたか確認します。

$ aws lightsail --region us-east-1 get-instances
{
    "instances": [
        {
            "username": "bitnami",
            "isStaticIp": false,
            "networking": {
                "monthlyTransfer": {
                    "gbPerMonthAllocated": 2000
                },
                "ports": [
                    {
                        "protocol": "tcp",
                        "accessType": "public",
                        "commonName": "",
                        "accessFrom": "Anywhere (0.0.0.0/0)",
                        "fromPort": 80,
                        "accessDirection": "inbound",
                        "toPort": 80
                    },
                    {
                        "protocol": "tcp",
                        "accessType": "public",
                        "commonName": "",
                        "accessFrom": "Anywhere (0.0.0.0/0)",
                        "fromPort": 22,
                        "accessDirection": "inbound",
                        "toPort": 22
                    },
                    {
                        "protocol": "tcp",
                        "accessType": "public",
                        "commonName": "",
                        "accessFrom": "Anywhere (0.0.0.0/0)",
                        "fromPort": 443,
                        "accessDirection": "inbound",
                        "toPort": 443
                    }
                ]
            },
            "name": "WordPress-2",
            "resourceType": "Instance",
            "supportCode": "015515485450/i-xxxxxxxxxxxxxxxxx",
            "blueprintName": "WordPress",
            "hardware": {
                "cpuCount": 1,
                "ramSizeInGb": 1.0
            },
            "privateIpAddress": "172.26.9.209",
            "state": {
                "code": 16,
                "name": "running"
            },
            "arn": "arn:aws:lightsail:us-east-1:xxxxxxxxxxxx:Instance/d61f5bf5-760b-43ac-b106-6548e97dc736",
            "publicIpAddress": "54.152.xxx.xxx",
            "blueprintId": "wordpress_4_6_1",
            "bundleId": "micro_1_0",
            "sshKeyName": "LightsailDefaultKeyPair",
            "createdAt": 1484778375.136,
            "location": {
                "availabilityZone": "us-east-1a",
                "regionName": "us-east-1"
            }
        }
    ]
}

元のインスタンス"name": "WordPress-1"がなくなり、"name": "WordPress-2"となりました。

これで Lightsailインスタンスのスケールアップは完了です!

まとめ

いかがでしょうか。

EC2と違い、LightsailではスケールアップするためにもSnapshot取得/インスタンスの再作成が必要でした。また、その操作はコンソールからはできず、AWS CLI が必要です。

また、今回CLIでLightsailを操作してみましたが、EC2に比べて設定項目も少なく、コンソールと同様に非常にシンプルだと感じました。

やはり、Lightsailの最大の魅力はそのシンプルさにあると再確認しました。