AWS CLI 명령을 사용하여 Lightsail 인스턴스를 관리하려면 어떻게 해야 하나요?
최종 업데이트 날짜: 2021년 1월 11일
AWS 명령줄 인터페이스(AWS CLI) 버전 1 명령을 사용하여 Amazon Lightsail 인스턴스를 관리하려면 어떻게 해야 하나요?
간략한 설명
Amazon Lightsail AWS CLI 명령 목록은 AWS CLI 명령 참조 및 Amazon Lightsail API 참조를 참조하세요.
다음은 Lightsail 인스턴스에서 AWS CLI 명령을 사용하는 일반적인 시나리오입니다.
- 리전에서 사용할 수 있는 모든 Lightsail 플랜(번들) 및 블루프린트를 나열합니다.
- 특정 번들 및 블루프린트를 사용하여 Lightsail 인스턴스를 생성합니다.
- 특정 리전의 모든 Lightsail 인스턴스를 나열합니다.
- 고정 IP 주소를 할당한 다음 인스턴스에 연결하고 확인합니다.
참고: AWS CLI 명령을 사용할 때는 다음 사항에 유의하세요.
- AWS CLI 명령을 실행할 때 오류가 발생하는 경우 최신 버전의 AWS CLI를 사용하고 있는지 확인하세요.
- JSON은 기본 AWS CLI 출력입니다. 기본값을 사용하거나 명령에 --output json을 추가하여 다음 예제와 같이 출력을 수신할 수 있습니다. 자세한 내용은 AWS CLI의 명령 출력 제어를 참조하세요.
- AWS CLI 오류 해결에 대한 일반적인 내용은 AWS CLI 명령을 실행할 때 오류가 발생하는 이유는 무엇입니까?를 참조하세요.
- AWS CLI 명령 출력은 Unix Epoch 시간으로 타임스탬프를 표시합니다. 다음 방법 중 하나를 사용하여 타임스탬프를 UTC로 변환합니다.
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 번들 및 블루프린트 나열하기
get-bundles 명령을 실행하여 해당 리전에서 구매할 수 있는 모든 번들 목록을 확인합니다. 다음 명령에서 eu-west-1을 사용자의 리전으로 바꿉니다.
# 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 |
| micro_2_0 | 1 | 40 | micro | 5.0 | 1.0 | LINUX_UNIX |
| small_2_0 | 1 | 60 | small | 10.0 | 2.0 | LINUX_UNIX |
| medium_2_0 | 2 | 80 | medium | 20.0 | 4.0 | LINUX_UNIX |
| large_2_0 | 2 | 160 | large | 40.0 | 8.0 | LINUX_UNIX |
| xlarge_2_0 | 4 | 320 | xlarge | 80.0 | 16.0 | LINUX_UNIX |
| 2xlarge_2_0 | 8 | 640 | 2xlarge | 160.0 | 32.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 |
| small_win_2_0 | 1 | 60 | small | 20.0 | 2.0 | WINDOWS |
| medium_win_2_0 | 2 | 80 | medium | 40.0 | 4.0 | WINDOWS |
| large_win_2_0 | 2 | 160 | large | 70.0 | 8.0 | WINDOWS |
| xlarge_win_2_0 | 4 | 320 | xlarge | 120.0 | 16.0 | WINDOWS |
| 2xlarge_win_2_0| 8 | 640 | 2xlarge | 240.0 | 32.0 | WINDOWS |
+-----------------+-----------+---------------+---------------+--------+---------------+----------------------+
get-blueprints 명령을 실행하여 해당 리전의 모든 이미지 또는 블루프린트 목록을 확인합니다. 그런 다음 사용 가능한 이미지를 사용하여 새 인스턴스를 생성하도록 선택할 수 있습니다. 다음 명령에서 eu-west-1을 사용자의 리전으로 바꿉니다.
# 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 |
| windows_server_2012 | windows_2012 | Windows Server 2012 R2 | WINDOWS | https://aws.amazon.com/marketplace/pp/B00KQOWCAQ |
| windows_server_2016_sql_2016_express| windows_2016_sql_exp | SQL Server 2016 Express | WINDOWS | https://aws.amazon.com/marketplace/pp/B01MAZHH98 |
| 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_20_04 | ubuntu_20 | Ubuntu | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B087QQNGF1 |
| ubuntu_18_04 | ubuntu_18 | Ubuntu | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B07CQ33QKV |
| ubuntu_16_04_2 | ubuntu | Ubuntu | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B01JBL2M0O |
| debian_10 | debian_10 | Debian | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B0859NK4HC |
| debian_9_5 | debian_9 | Debian | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B073HW9SP3 |
| debian_8_7 | debian | Debian | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B00WUNJIEE |
| freebsd_12 | freebsd | FreeBSD | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B07L6QV354 |
| opensuse_15_1 | opensuse | openSUSE | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B01N4R3GJI |
| centos_7_1901_01 | centos | CentOS | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B00O7WM7QW |
| 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 |
| lamp_7 | lamp_7 | LAMP (PHP 7) | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B072JNJZ5C |
| nodejs | node | Node.js | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B00NNZUAKO |
| joomla | joomla | Joomla | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B00NNZUP54 |
| magento | magento | Magento | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B00NNZTA6Y |
| mean | mean | MEAN | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B00NO1HJ56 |
| drupal | drupal | Drupal | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B00NNZSUMO |
| gitlab | gitlab | GitLab CE | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B00NNZU5PO |
| redmine | redmine | Redmine | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B00NNZUVHQ |
| nginx | nginx | Nginx | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B00NPHKI3Y |
| ghost_bitnami | ghost_bitnami | Ghost | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B00NPHLY8W |
| django_bitnami | django_bitnami | Django | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B00NNZTDNO |
| plesk_ubuntu_18_0_28 | plesk_ubuntu | Plesk Hosting Stack on Ubuntu | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B077MJL7Z2 |
| cpanel_whm_linux | cpanel_whm_linux | cPanel & WHM for Linux | LINUX_UNIX | https://aws.amazon.com/marketplace/pp/B07RRX2TVV |
+--------------------------------------+-----------------------+--------------------------------+-------------+-----------------------------------------------------+
예:
다음 명령은 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 |
| Ubuntu | 18.04 LTS |
| Ubuntu | 16.04 LTS |
| Debian | 10.5 |
| Debian | 9.5 |
| Debian | 8.7 |
| FreeBSD | 12.1 |
| openSUSE | 15.1 |
| CentOS | 7 1901-01 |
+-----------------+------------------------+
특정 번들 및 블루프린트를 사용하여 Lightsail 인스턴스 생성하기
1. 다음 명령을 실행하여 블루프린트를 가져옵니다. 다음 예시 명령은 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 |
2. create-instances 명령을 실행하여 Amazon Lightsail 인스턴스를 생성합니다. 다음 예시에서는 WordPress 블루프린트 및 micro_2_0 번들을 사용하여 eu-west-1 리전에서 Amazon Lightsail 인스턴스를 생성합니다. --instance-names, blueprint-id, bundle-id, --region을 요청에 적합한 값으로 바꿉니다.
# 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
}
]
}
단일 API 호출을 사용하여 여러 인스턴스를 생성하려면 파라미터를 --instance-names {"LightsailInstance1","LightsailInstance2"}로 지정합니다. 다음 예시에서는 WordPress 블루프린트 및 micro_2_0 번들을 사용하여 eu-west-1 리전에 2개의 Lightsail 인스턴스를 생성합니다.
# 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 인스턴스를 보여줍니다. --region을 요청에 적합한 값으로 바꿔줍니다.
# 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 |
| wordpress | WordPress | 1602175452.334 | MyNewInstance | 54.195.xx.xx
+-----------------+----------------+-----------------+------------------------------------------+-------------------+
고정 IP를 할당한 다음 생성된 Lightsail 인스턴스에 연결하고 이를 확인합니다.
참고: create-instances 명령은 퍼블릭 IP 주소가 할당된 Lightsail 인스턴스를 만듭니다. 인스턴스나 다른 리소스에 할당하고 재할당할 수 있는 퍼블릭 IP 주소와 달리 고정 IP 주소는 고정됩니다. 인스턴스에 대한 고정 IP 주소를 생성하지 않은 경우 인스턴스를 중지하거나 다시 시작할 때마다 Lightsail에서 새 퍼블릭 IP 주소를 할당합니다.
1. 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
}
]
}
2. 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
}
}
3. attach-static-ip명령을 실행하여 고정 IP 주소를 Lightsail 인스턴스에 연결합니다. 다음 예에서는 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
}
]
}
4. 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 |
+----------------------------------+------------------+----------------+-----------------+------------------------------------------+-------------------+