将 DescribeInstanceInformation 与 CLI 配合使用 - AWS Systems Manager

DescribeInstanceInformation 与 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 用户指南》中的托管式实例

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-1AgentVersion2.2.800.0 的 AWS Systems Manager 实例。您可以在 InstanceInformation API 参考主题(https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_InstanceInformation.html#systemsmanager-Type-InstanceInformation-ActivationId)中找到有效的 -Filter 键值列表。

$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-1PlatformTypesWindowsLinux 的 AWS Systems Manager 实例。您可以在 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

有关 AWS SDK 开发人员指南和代码示例的完整列表,请参阅 将 Systems Manager 与 AWS SDK 配合使用。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。