Knowledge Center Monthly Newsletter - March 2025
Stay up to date with the latest from the Knowledge Center. See all new and updated Knowledge Center articles published in the last month and re:Post’s top contributors.
如何使用 AWS CLI 管理 Lightsail 实例上的静态 IP 地址?
我想使用 AWS CLI 将静态 IP 地址与 Amazon Lightsail 实例分离,并将其连接到新的 Lightsail 实例。
简短描述
有关 Lightsail AWS 命令行界面(AWS CLI)命令的列表,请参阅 AWS CLI Command Reference 和 Amazon Lightsail API Reference。
重要事项:
- 如果在运行 AWS CLI 命令时收到错误,请参阅 Troubleshoot AWS CLI errors。此外,确保您使用的是最新版本的 AWS CLI。
- AWS CLI 的默认输出格式为 JSON。您可以使用默认值,也可以将 --output json 附加到命令以接收输出。有关更多信息,请参阅 Control command output from the 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 网站上的 Epoch & Unix Timestamp Conversion Tools。
解决方法
将静态 IP 地址与现有 Lightsail 实例分离
运行 detach-static-ip 命令,将静态 IP 地址与实例分离:
# 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 } ] }
**注意:**在前面的示例中,将 --static-ip-name 和 --region 替换为您的值。该示例将静态 IP 地址与 AWS 区域 eu-west-1 中的实例分离。
将该静态 IP 地址连接到新的 Lightsail 实例
要将静态 IP 地址连接到您的 Lightsail 实例,请完成以下步骤:
- 运行 attach-static-ip 命令:
注意:在前面的命令中,将 --static-ip-name、--instance-name 和 --region 替换为您的值。该命令使用备份将静态 IP 地址附加到新实例。# 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 } ]
- 运行 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 实例创建备份?
Activate or deactivate automatic snapshots for Lightsail instances and disks

相关内容
- AWS 官方已更新 9 个月前
- AWS 官方已更新 1 年前
- AWS 官方已更新 2 年前
- AWS 官方已更新 1 年前