AWS announces preview of AWS Interconnect - multicloud
AWS announces AWS Interconnect – multicloud (preview), providing simple, resilient, high-speed private connections to other cloud service providers. AWS Interconnect - multicloud is easy to configure and provides high-speed, resilient connectivity with dedicated bandwidth, enabling customers to interconnect AWS networking services such as AWS Transit Gateway, AWS Cloud WAN, and Amazon VPC to other cloud service providers with ease.
AWS CLI のコマンドを使用して Lightsail インスタンスを管理する方法を教えてください。
AWS コマンドラインインターフェイス (AWS CLI) のコマンドを使用して Amazon Lightsail インスタンスを管理したいと考えています。
簡単な説明
AWS CLI のコマンドを Lightsail インスタンスで使用するための一般的なシナリオには次のようなものがあります。
- AWS リージョンで利用可能な Lightsail プラン (バンドル) とブループリントをすべて一覧表示する
- 特定のバンドルとブループリントを使用して Lightsail インスタンスを作成する
- 特定のリージョンの Lightsail インスタンスをすべて一覧表示する
- 静的 IP アドレスを割り当て、インスタンスにアタッチして検証する
注:
- AWS CLI のコマンドの実行時にエラーが発生する場合は、「AWS CLI エラーのトラブルシューティング」を参照してください。また、AWS CLI の最新バージョンを使用していることを確認してください。
- JSON は AWS CLI のデフォルト出力です。他に、コマンド末尾に --output json を追加すると、次の例に示すような出力が得られます。詳細については、「AWS CLI からのコマンド出力を制御する」を参照してください。
- AWS CLI のコマンド出力には、Unix エポック時間のタイムスタンプが表示されます。タイムスタンプを UTC に変換するには、次のいずれかの方法を使用します。
macOS
タイムスタンプから小数点を削除し、小数点の右に数字があればそれもすべて削除します。それから次のコマンドを実行します。
# date -r 1602175741 -uThu Oct 8 16:49:01 UTC 2020
Linux
以下のコマンドを実行します:
# date -d @1602175741.603 -uThu Oct 8 16:49:01 UTC 2020
Windows
epochconverter.com などのコンバーターを使用して、タイムスタンプを変換します。
解決方法
リージョンで利用可能な Lightsail バンドルとブループリントを一覧表示する
get-bundles コマンドを実行し、自分のリージョンで扱っているバンドルを一覧表示します。次に示すのは出力サンプルです。
# aws lightsail get-bundles --region eu-west-1 --query 'bundles[].{price:price,cpuCount:cpuCount,ramSizeInGb:ramSizeInGb,diskSizeInGb:diskSizeInGb,bundleId:bundleId,instanceType:instanceType,supportedPlatforms:supportedPlatforms[0]}' --output table --------------------------------------------------------------------------------------------------------------- | GetBundles | +-----------------+-----------+---------------+---------------+--------+---------------+----------------------+ | bundleId | cpuCount | diskSizeInGb | instanceType | price | ramSizeInGb | supportedPlatforms | +-----------------+-----------+---------------+---------------+--------+---------------+----------------------+ | nano_2_0 | 1 | 20 | nano | 3.5 | 0.5 | LINUX_UNIX | | small_2_0 | 1 | 60 | small | 10.0 | 2.0 | LINUX_UNIX | | nano_win_2_0 | 1 | 30 | nano | 8.0 | 0.5 | WINDOWS | | micro_win_2_0 | 1 | 40 | micro | 12.0 | 1.0 | WINDOWS | +-----------------+-----------+---------------+---------------+--------+---------------+----------------------+
注: eu-west-1 は自分のリージョンに置き換えてください。
get-blueprints コマンドを実行すると、自分のリージョンにあるイメージやブループリントがすべて一覧表示されます。次に示すのは出力サンプルです。
# aws lightsail get-blueprints --region eu-west-1 --query 'blueprints[].{blueprintId:blueprintId,name:name,group:group,productUrl:productUrl,platform:platform}' --output table --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | GetBlueprints | +--------------------------------------+-----------------------+--------------------------------+-------------+-----------------------------------------------------+ | blueprintId | group | name | platform | productUrl | +--------------------------------------+-----------------------+--------------------------------+-------------+-----------------------------------------------------+ | windows_server_2019 | windows_2019 | Windows Server 2019 | WINDOWS | https://aws.amazon.com/marketplace/pp/B07QZ4XZ8F | | windows_server_2016 | windows_2016 | Windows Server 2016 | WINDOWS | https://aws.amazon.com/marketplace/pp/B01M7SJEU7 | | amazon_linux_2 | amazon_linux_2 | Amazon Linux 2 | LINUX_UNIX | https://aws.amazon.com/amazon-linux-2/ | | amazon_linux | amazon-linux | Amazon Linux | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B00CIYTQTC | | ubuntu_18_04 | ubuntu_18 | Ubuntu | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B07CQ33QKV | | debian_10 | debian_10 | Debian | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B0859NK4HC | +--------------------------------------+-----------------------+--------------------------------+-------------+-----------------------------------------------------+
注: eu-west-1 は自分のリージョンに置き換えてください。
必要とするプラットフォームのブループリントをフィルタリングします。たとえば、次のコマンドでは Linux/Unix プラットフォーム OS のブループリントがフィルタリングされます。
# aws lightsail get-blueprints --query 'blueprints[?type==`os`&&platform==`LINUX_UNIX`].{name:name,version:version}'--output table -------------------------------------------- | GetBlueprints | +-----------------+------------------------+ | name | version | +-----------------+------------------------+ | Amazon Linux 2 | 2.0.20200917.0 | | Amazon Linux | 2018.03.0.20200918.0 | | Ubuntu | 20.04 LTS | | Debian | 10.5 | | openSUSE | 15.1 | | CentOS | 7 1901-01 | +-----------------+------------------------+
特定のバンドルとブループリントを使用して Lightsail インスタンスを作成する
- get-blueprint コマンドを実行します。次の例では、WordPress のブループリントが取得されます。
注: eu-west-1 は自分のリージョンに、WordPressの情報は自分のブループリント情報に置き換えてください。# aws lightsail get-blueprints --region eu-west-1 --query 'blueprints[].{blueprintId:blueprintId,name:name,group:group,productUrl:productUrl,platform:platform}' --output table |grep -i wordpress | wordpress | wordpress | WordPress | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B00NN8Y43U | | wordpress_multisite | wordpress_multisite | WordPress Multisite | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B00NN8XE6S | - create-instances コマンドを実行して Amazon Lightsail インスタンスを作成します。次の例では、WordPress ブループリントと micro_2_o バンドルを使用して、Amazon Lightsail インスタンスを eu-west-1 リージョンに作成しています。
注: instance-names、blueprint-id, bundle-id、region は、該当する値に置き換えてください。API コールを1回使用するだけで複数のインスタンスを作成するには、--instance-names にパラメーター (LightsailInstance1 や LightsailInstance2 など) を指定してください。次の例では、WordPress ブループリントと micro_2_0 バンドルを使用して、Lightsail インスタンスを2つ eu-west-1 リージョンに作成しています。# aws lightsail create-instances --region eu-west-1 --instance-names MyNewInstance --availability-zone eu-west-1a --blueprint-id wordpress --bundle-id micro_2_0 { "operations": [ { "id": "003757e7-0880-4162-9912-211d4756081e", "resourceName": "MyNewInstance", "resourceType": "Instance", "createdAt": 1602175452.334, "location": { "availabilityZone": "eu-west-1a", "regionName": "eu-west-1" }, "isTerminal": false, "operationType": "CreateInstance", "status": "Started", "statusChangedAt": 1602175452.334 } ] }# aws lightsail create-instances --region eu-west-1 --instance-names {"TestLightsailInstance1","TestLightsailInstance2"} --availability-zone eu-west-1a --blueprint-id wordpress --bundle-id micro_2_0 { "operations": [ { "id": "8a15b195-9a20-4d79-ad1d-6e85557ae94d", "resourceName": "TestLightsailInstance1", "resourceType": "Instance", "createdAt": 1602175741.602, "location": { "availabilityZone": "eu-west-1a", "regionName": "eu-west-1" }, "isTerminal": false, "operationType": "CreateInstance", "status": "Started", "statusChangedAt": 1602175741.602 }, { "id": "a006513b-0e25-4802-ab33-671a40bf5a92", "resourceName": "TestLightsailInstance2", "resourceType": "Instance", "createdAt": 1602175741.603, "location": { "availabilityZone": "eu-west-1a", "regionName": "eu-west-1" }, "isTerminal": false, "operationType": "CreateInstance", "status": "Started", "statusChangedAt": 1602175741.603 } ] }
リージョンにある Lightsail インスタンスをすべて一覧表示する
get-instances コマンドを実行して特定のリージョンの Lightsail インスタンスを表示します。次の例では、eu-west-1 リージョンの Lightsail インスタンスを示しています。
# aws lightsail get-instances --region eu-west-1 --query 'instances[].{name:name,createdAt:createdAt,blueprintId:blueprintId,blueprintName:blueprintName,publicIpAddress:publicIpAddress}' --output table --------------------------------------------------------------------------------------------------------------------- | GetInstances | +-----------------+----------------+-----------------+------------------------------------------+-------------------+ | blueprintId | blueprintName | createdAt | name | publicIpAddress | +-----------------+----------------+-----------------+------------------------------------------+-------------------+ | wordpress_4_9_8| WordPress | 1545700733.77 | WordPress-512MB-Ireland-1 | 63.33.xx.xx | | wordpress | WordPress | 1602175741.603 | TestLightsailInstance2 | 63.33.xx.xx | | wordpress | WordPress | 1602175741.602 | TestLightsailInstance1 | 54.7.xx.xx | | wordpress | WordPress | 1588098501.555 | WordPress-1 | 3.250.xx.xx | +-----------------+----------------+-----------------+------------------------------------------+-------------------+
注: region は自分のリージョンに置き換えてください。
作成した Lightsail インスタンスに静的 IP を割り当ててアタッチする
注: create-instances コマンドでは、Lightsail インスタンスをパブリック IP アドレスで作成します。インスタンスの静的 IP アドレスを作成していない場合は、インスタンスを停止するか再起動するたびに Lightsail で新しいパブリック IP アドレスが割り当てられます。
- allocate-static-ip コマンドを実行して、固定パブリックアドレスを割り当てます。次の例では、eu-west-1 リージョンでの StaticIpForTestLightsailInstance1 という名前の静的 IP の割り当てを示しています。
注: static-ip-name および region は、該当する値に置き換えてください。# aws lightsail allocate-static-ip --static-ip-name StaticIpForTestLightsailInstance1 --region eu-west-1 { "operations": [ { "id": "6471cedc-97f5-42d1-b35f-4f77c5f93242", "resourceName": "StaticIpForTestLightsailInstance1", "resourceType": "StaticIp", "createdAt": 1602180341.746, "location": { "availabilityZone": "all", "regionName": "eu-west-1" }, "isTerminal": true, "operationType": "AllocateStaticIp", "status": "Succeeded", "statusChangedAt": 1602180342.011 } ] } - get-static-ip コマンドを実行して、割り当てられた静的 IP アドレスの値を表示します。次の例では、eu-west-1 リージョンでの StaticIpForTestLightsailInstance1 という名前の静的 IP 52.210.xx.xx の割り当てを示しています。
注: static-ip-name および region は、該当する値に置き換えてください。# aws lightsail get-static-ip --static-ip-name StaticIpForTestLightsailInstance1 --region eu-west-1 { "staticIp": { "name": "StaticIpForTestLightsailInstance1", "arn": "arn:aws:lightsail:eu-west-1:920893848407:StaticIp/16a97579-c51e-404c-96cc-5946528d12aa", "supportCode": "11178xxxxxxx/52.210.xx.xx", "createdAt": 1602180341.746, "location": { "availabilityZone": "all", "regionName": "eu-west-1" }, "resourceType": "StaticIp", "ipAddress": "52.210.xx.xx", "isAttached": false } } - attach-static-ip コマンドを実行します。次の例では、eu-west-1 リージョンでの StaticIpForTestLightsailInstance1 という名前の静的 IP 52.210.xx.xx の TestLightsailInstance1 という名前のインスタンスへの割り当てを示しています。
注: static-ip-name、instance-name、region は、該当する値に置き換えてください。# aws lightsail attach-static-ip --static-ip-name StaticIpForTestLightsailInstance1 --instance-name TestLightsailInstance1 --region eu-west-1 { "operations": [ { "id": "d9d2372f-b4b7-4838-99ae-c15f8ffb8332", "resourceName": "StaticIpForTestLightsailInstance1", "resourceType": "StaticIp", "createdAt": 1602180562.026, "location": { "availabilityZone": "all", "regionName": "eu-west-1" }, "isTerminal": true, "operationDetails": "TestLightsailInstance1", "operationType": "AttachStaticIp", "status": "Succeeded", "statusChangedAt": 1602180562.026 }, { "id": "131994d8-bd25-4b47-8d81-851224b168d1", "resourceName": "TestLightsailInstance1", "resourceType": "Instance", "createdAt": 1602180562.026, "location": { "availabilityZone": "eu-west-1a", "regionName": "eu-west-1" }, "isTerminal": true, "operationDetails": "StaticIpForTestLightsailInstance1", "operationType": "AttachStaticIp", "status": "Succeeded", "statusChangedAt": 1602180562.026 } ] } - get-instances コマンドを実行して、静的 IP アドレスが Lightsail インスタンスと正しく関連付けられていることを確認します。
# aws lightsail get-instances --region eu-west-1 --query 'instances[].{name:name,createdAt:createdAt,blueprintId:blueprintId,blueprintName:blueprintName,publicIpAddress:publicIpAddress,InstanceID:supportCode}' --output table --------------------------------------------------------------------------------------------------------------------------------------------------------- | GetInstances | +----------------------------------+------------------+----------------+-----------------+------------------------------------------+-------------------+ | InstanceID | blueprintId | blueprintName | createdAt | name | publicIpAddress | +----------------------------------+------------------+----------------+-----------------+------------------------------------------+-------------------+ | 11178xxxxxxx/i-09f6xxxx | wordpress | WordPress | 1602175741.602 | TestLightsailInstance1 | 52.210.xx.xx | +----------------------------------+------------------+----------------+-----------------+------------------------------------------+-------------------+
関連情報
AWS CLI コマンドを使用してスナップショットを管理したり Lightsail インスタンスのバックアップを作成したりするにはどうすればよいですか?
AWS CLI コマンドを使用して Lightsail インスタンスの静的 IP アドレスを管理するにはどうすればよいですか?
