DescribeInstanceInformation 搭配 使用 CLI - AWS SDK 程式碼範例

文件範例儲存庫中有更多 AWS SDK可用的範例。 AWS SDK GitHub

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

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-1具有 AgentVersion 之 區域中的 AWS Systems Manager 執行個體2.2.800.0。您可以在參考主題 (https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_InstanceInformation.html#systemsmanager-TypeInstanceInformation-) InstanceInformation API中找到有效 -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 parameter 將結果篩選至 Windows或 區域中us-east-1PlatformTypes的 AWS Systems Manager 執行個體Linux。您可以在參考主題 (https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_.html) InstanceInformationFilter API中找到有效 InstanceInformationFilterList 鍵值的清單InstanceInformationFilter。

$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