aws:runCommand - 在托管实例上运行命令 - Amazon Systems Manager
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

aws:runCommand - 在托管实例上运行命令

运行指定的命令。

注意

自动化仅支持 Amazon Systems Manager Run Command 操作的一个输出。一个运行手册可以包括多个 Run Command 操作,但一次仅支持对一个操作输出。

输入

此操作支持大多数 send command 参数。有关更多信息,请参阅SendCommand

YAML
- name: checkMembership action: 'aws:runCommand' inputs: DocumentName: AWS-RunPowerShellScript InstanceIds: - '{{InstanceIds}}' Parameters: commands: - (Get-WmiObject -Class Win32_ComputerSystem).PartOfDomain
JSON
{ "name": "checkMembership", "action": "aws:runCommand", "inputs": { "DocumentName": "AWS-RunPowerShellScript", "InstanceIds": [ "{{InstanceIds}}" ], "Parameters": { "commands": [ "(Get-WmiObject -Class Win32_ComputerSystem).PartOfDomain" ] } } }
DocumentName

如果命令类型文档属于您或 Amazon,请指定文档的名称。如果您使用的是另一个 Amazon Web Services 账户与您共享的文档,指定文档的 Amazon Resource Name (ARN)。有关如何使用共享文档的更多信息,请参阅 使用共享 SSM 文档

类型:字符串

必需:是

InstanceIds

要在其中运行命令的实例 ID。您可以指定最多 50 个 ID。

您还可以使用虚拟参数 {{RESOURCE_ID}} 代替实例 ID,以便在目标组中的所有实例上运行命令。有关虚拟参数的更多信息,请参阅 关于虚拟参数

另一种替代方法是使用 Targets 参数向一组实例发送命令。Targets 参数接受 Amazon Elastic Compute Cloud (Amazon EC2) 标签。有关如何使用 Targets 参数的更多信息,请参阅 大规模运行命令

类型: StringList

必需:否(如果未指定 InstanceIds 或使用{{RESOURCE_ID}}虚拟参数,则必须指定 IDTargets 参数。)

目标

一组搜索条件,使用您指定的键/值组合来设置实例目标。如果未在调用中提供一个或多个实例 ID,则 Targets 为必需。有关如何使用 Targets 参数的更多信息,请参阅 大规模运行命令

类型: MapList (列表中地图的架构必须与对象匹配。有关更多信息,请参阅 Amazon Systems ManagerAPI 参考中的目标

必需:否(如果未指定Targets,则必须指定 InstanceIds 或{{RESOURCE_ID}}使用虚拟参数。)

以下为示例。

YAML
- name: checkMembership action: aws:runCommand inputs: DocumentName: AWS-RunPowerShellScript Targets: - Key: tag:Stage Values: - Gamma - Beta - Key: tag-key Values: - Suite Parameters: commands: - (Get-WmiObject -Class Win32_ComputerSystem).PartOfDomain
JSON
{ "name": "checkMembership", "action": "aws:runCommand", "inputs": { "DocumentName": "AWS-RunPowerShellScript", "Targets": [ { "Key": "tag:Stage", "Values": [ "Gamma", "Beta" ] }, { "Key": "tag:Application", "Values": [ "Suite" ] } ], "Parameters": { "commands": [ "(Get-WmiObject -Class Win32_ComputerSystem).PartOfDomain" ] } } }
参数

文档中指定的必需参数和可选参数。

类型:映射

必需:否

CloudWatchOutputConfig

用于将命令发送发送发送发送发送发送发送发送发送发送发送发送发送发送发送发送发送发送 CloudWatch 有关将发送发送发送发送发送发送发送发送发送发送发送发送发送发送发送发送发送发送发送发送发送发送发送 CloudWatch 为其配置亚马逊CloudWatch日志Run Command

类型: StringMap (地图的架构必须与对象匹配。 有关更多信息,请参阅 CloudWatchOutputConfigAmazon Systems ManagerAPI 参考中的)。

必需:否

以下为示例。

YAML
- name: checkMembership action: aws:runCommand inputs: DocumentName: AWS-RunPowerShellScript InstanceIds: - "{{InstanceIds}}" Parameters: commands: - "(Get-WmiObject -Class Win32_ComputerSystem).PartOfDomain" CloudWatchOutputConfig: CloudWatchLogGroupName: CloudWatchGroupForSSMAutomationService CloudWatchOutputEnabled: true
JSON
{ "name": "checkMembership", "action": "aws:runCommand", "inputs": { "DocumentName": "AWS-RunPowerShellScript", "InstanceIds": [ "{{InstanceIds}}" ], "Parameters": { "commands": [ "(Get-WmiObject -Class Win32_ComputerSystem).PartOfDomain" ] }, "CloudWatchOutputConfig" : { "CloudWatchLogGroupName": "CloudWatchGroupForSSMAutomationService", "CloudWatchOutputEnabled": true } } }
Comment

有关此命令的用户定义的信息。

类型:字符串

必需:否

DocumentHash

文档的哈希。

类型:字符串

必需:否

DocumentHashType

哈希的类型。

类型:字符串

有效值:Sha256 | Sha1

必需:否

NotificationConfig

用于发送通知的配置。

必需:否

产出 3BucketName

命令输出响应的 S3 存储桶的名称。

类型:字符串

必需:否

产出 3KeyPrefix

前缀。

类型:字符串

必需:否

ServiceRoleArn

Amazon Identity and Access Management (IAM) 角色的 ARN。

类型:字符串

必需:否

TimeoutSeconds

等待命令传递到实例上的 Amazon Systems Manager SSM Agent 的时间(单位:秒)。如果在达到指定的值之前,命令未被实例上的 SSM Agent 接收,则命令的状态将更改为 Delivery Timed Out

类型:整数

必需:否

Output
CommandId

命令的 ID。

状态

命令的状态。

ResponseCode

命令的响应代码。

Output

命令的输出。