AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
DescribeInstanceInformation
与 a 一起使用 CLI
以下代码示例演示如何使用 DescribeInstanceInformation
。
- CLI
-
- AWS CLI
-
示例 1:描述托管式实例信息
以下
describe-instance-information
示例检索每个托管式实例的详细信息。aws ssm describe-instance-information
示例 2:描述有关特定托管式实例的信息
以下
describe-instance-information
示例显示托管式实例i-028ea792daEXAMPLE
的详细信息。aws ssm describe-instance-information \ --filters
"Key=InstanceIds,Values=i-028ea792daEXAMPLE"
示例 3:描述有关具有特定标签键的托管式实例的信息
以下
describe-instance-information
示例显示具有标签键DEV
的托管式实例的详细信息。aws ssm describe-instance-information \ --filters
"Key=tag-key,Values=DEV"
输出:
{ "InstanceInformationList": [ { "InstanceId": "i-028ea792daEXAMPLE", "PingStatus": "Online", "LastPingDateTime": 1582221233.421, "AgentVersion": "2.3.842.0", "IsLatestVersion": true, "PlatformType": "Linux", "PlatformName": "SLES", "PlatformVersion": "15.1", "ResourceType": "EC2Instance", "IPAddress": "192.0.2.0", "ComputerName": "ip-198.51.100.0.us-east-2.compute.internal", "AssociationStatus": "Success", "LastAssociationExecutionDate": 1582220806.0, "LastSuccessfulAssociationExecutionDate": 1582220806.0, "AssociationOverview": { "DetailedStatus": "Success", "InstanceAssociationStatusAggregatedCount": { "Success": 2 } } } ] }
有关更多信息,请参阅《AWS Systems Manager 用户指南》中的托管式实例。
-
有关API详细信息,请参阅 “DescribeInstanceInformation AWS CLI
命令参考”。
-
- PowerShell
-
- 用于 PowerShell
-
示例 1:此示例显示每个实例的详细信息。
Get-SSMInstanceInformation
输出:
ActivationId : AgentVersion : 2.0.672.0 AssociationOverview : Amazon.SimpleSystemsManagement.Model.InstanceAggregatedAssociationOverview AssociationStatus : Success ComputerName : ip-172-31-44-222.us-west-2.compute.internal IamRole : InstanceId : i-0cb2b964d3e14fd9f IPAddress : 172.31.44.222 IsLatestVersion : True LastAssociationExecutionDate : 2/24/2017 3:18:09 AM LastPingDateTime : 2/24/2017 3:35:03 AM LastSuccessfulAssociationExecutionDate : 2/24/2017 3:18:09 AM Name : PingStatus : ConnectionLost PlatformName : Amazon Linux AMI PlatformType : Linux PlatformVersion : 2016.09 RegistrationDate : 1/1/0001 12:00:00 AM ResourceType : EC2Instance
示例 2:此示例说明如何使用-Filter 参数将结果筛选到区域
us-east-1
中仅为AgentVersion
的2.2.800.0
那些 AWS 系统管理器实例。你可以在 InstanceInformation API参考主题 (https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_ InstanceInformation .html #systemsmanager-Type--InstanceInformation) 中找到有效的-Filter 键值列表。ActivationId$Filters = @{ Key="AgentVersion" Values="2.2.800.0" } Get-SSMInstanceInformation -Region us-east-1 -Filter $Filters
输出:
ActivationId : AgentVersion : 2.2.800.0 AssociationOverview : Amazon.SimpleSystemsManagement.Model.InstanceAggregatedAssociationOverview AssociationStatus : Success ComputerName : EXAMPLE-EXAMPLE.WORKGROUP IamRole : InstanceId : i-EXAMPLEb0792d98ce IPAddress : 10.0.0.01 IsLatestVersion : False LastAssociationExecutionDate : 8/16/2018 12:02:50 AM LastPingDateTime : 8/16/2018 7:40:27 PM LastSuccessfulAssociationExecutionDate : 8/16/2018 12:02:50 AM Name : PingStatus : Online PlatformName : Microsoft Windows Server 2016 Datacenter PlatformType : Windows PlatformVersion : 10.0.14393 RegistrationDate : 1/1/0001 12:00:00 AM ResourceType : EC2Instance ActivationId : AgentVersion : 2.2.800.0 AssociationOverview : Amazon.SimpleSystemsManagement.Model.InstanceAggregatedAssociationOverview AssociationStatus : Success ComputerName : EXAMPLE-EXAMPLE.WORKGROUP IamRole : InstanceId : i-EXAMPLEac7501d023 IPAddress : 10.0.0.02 IsLatestVersion : False LastAssociationExecutionDate : 8/16/2018 12:00:20 AM LastPingDateTime : 8/16/2018 7:40:35 PM LastSuccessfulAssociationExecutionDate : 8/16/2018 12:00:20 AM Name : PingStatus : Online PlatformName : Microsoft Windows Server 2016 Datacenter PlatformType : Windows PlatformVersion : 10.0.14393 RegistrationDate : 1/1/0001 12:00:00 AM ResourceType : EC2Instance
示例 3:此示例说明如何使用-InstanceInformationFilterList 参数筛选结果,仅筛选区域中
us-east-1
带Windows
或PlatformTypes
的那些 AWS 系统管理器实例Linux
。您可以在 InstanceInformationFilter API参考主题 (https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_ InstanceInformationFilter .html) 中找到有效的InstanceInformationFilterList 键值列表。$Filters = @{ Key="PlatformTypes" ValueSet=("Windows","Linux") } Get-SSMInstanceInformation -Region us-east-1 -InstanceInformationFilterList $Filters
输出:
ActivationId : AgentVersion : 2.2.800.0 AssociationOverview : Amazon.SimpleSystemsManagement.Model.InstanceAggregatedAssociationOverview AssociationStatus : Success ComputerName : EXAMPLE-EXAMPLE.WORKGROUP IamRole : InstanceId : i-EXAMPLEb0792d98ce IPAddress : 10.0.0.27 IsLatestVersion : False LastAssociationExecutionDate : 8/16/2018 12:02:50 AM LastPingDateTime : 8/16/2018 7:40:27 PM LastSuccessfulAssociationExecutionDate : 8/16/2018 12:02:50 AM Name : PingStatus : Online PlatformName : Ubuntu Server 18.04 LTS PlatformType : Linux PlatformVersion : 18.04 RegistrationDate : 1/1/0001 12:00:00 AM ResourceType : EC2Instance ActivationId : AgentVersion : 2.2.800.0 AssociationOverview : Amazon.SimpleSystemsManagement.Model.InstanceAggregatedAssociationOverview AssociationStatus : Success ComputerName : EXAMPLE-EXAMPLE.WORKGROUP IamRole : InstanceId : i-EXAMPLEac7501d023 IPAddress : 10.0.0.100 IsLatestVersion : False LastAssociationExecutionDate : 8/16/2018 12:00:20 AM LastPingDateTime : 8/16/2018 7:40:35 PM LastSuccessfulAssociationExecutionDate : 8/16/2018 12:00:20 AM Name : PingStatus : Online PlatformName : Microsoft Windows Server 2016 Datacenter PlatformType : Windows PlatformVersion : 10.0.14393 RegistrationDate : 1/1/0001 12:00:00 AM ResourceType : EC2Instance
示例 4:此示例列出了 ssm 托管实例以及导出 InstanceId PingStatus、 LastPingDateTime 和 PlatformName csv 文件。
Get-SSMInstanceInformation | Select-Object InstanceId, PingStatus, LastPingDateTime, PlatformName | Export-Csv Instance-details.csv -NoTypeInformation
-
有关API详细信息,请参阅 AWS Tools for PowerShell Cmdlet 参考DescribeInstanceInformation中的。
-