1 回答
- 最新
- 投票最多
- 评论最多
0
【以下的回答经过翻译处理】 这是我使用自动化文档 ( automation document) 完成的,受到 AWS-User-7841548 的回复的启示。它将针对正在运行 SSM 代理的实例。过滤器相当于 aws ssm describe-instance-information --filter "Key=InstanceIds,Values=xxx"
。
description: "changeme"
schemaVersion: '0.3'
assumeRole: '{{AutomationAssumeRole}}'
outputs:
- runShellCommandLinux.Output
- runPowerShellCommand.Output
- runShellCommandMac.Output
parameters:
AutomationAssumeRole:
default: ''
type: String
InstanceId:
description: (Required) EC2 InstanceId to run command
type: String
mainSteps:
- name: GetInstance
action: 'aws:executeAwsApi'
inputs:
Service: ssm
Api: DescribeInstanceInformation
Filters:
- Key: InstanceIds
Values:
- '{{ InstanceId }}'
outputs:
- Name: myInstance
Selector: '$.InstanceInformationList[0].InstanceId'
Type: String
- Name: platform
Selector: '$.InstanceInformationList[0].PlatformType'
Type: String
- Name: PingStatus
Selector: '$.InstanceInformationList[0].PingStatus'
Type: String
- Name: ResourceType
Selector: '$.InstanceInformationList[0].ResourceType'
Type: String
- name: SelectOnlineInstances
action: 'aws:branch'
isEnd: true
inputs:
Choices:
- And:
- Variable: '{{GetInstance.PingStatus}}'
StringEquals: Online
- Variable: '{{GetInstance.ResourceType}}'
StringEquals: EC2Instance
NextStep: ChoosePlatform
- name: ChoosePlatform
action: 'aws:branch'
isEnd: true
inputs:
Choices:
- NextStep: runPowerShellCommand
Variable: '{{GetInstance.platform}}'
StringEquals: Windows
- NextStep: runShellCommandLinux
Variable: '{{GetInstance.platform}}'
StringEquals: Linux
- NextStep: runShellCommandMac
Variable: '{{GetInstance.platform}}'
StringEquals: MacOS
- name: runShellCommandLinux
action: 'aws:runCommand'
isEnd: true
inputs:
DocumentName: AWS-RunShellScript
InstanceIds:
- '{{GetInstance.myInstance}}'
Parameters:
commands:
- echo "hello from linux"
- name: runPowerShellCommand
action: 'aws:runCommand'
isEnd: true
inputs:
DocumentName: AWS-RunPowerShellScript
InstanceIds:
- '{{GetInstance.myInstance}}'
Parameters:
commands:
- Write-Output "hello from windows"
- name: runShellCommandMac
action: 'aws:runCommand'
isEnd: true
inputs:
DocumentName: AWS-RunShellScript
InstanceIds:
- '{{GetInstance.myInstance}}'
Parameters:
commands:
- echo "hello from mac"
相关内容
- AWS 官方已更新 6 个月前
- AWS 官方已更新 10 个月前
- AWS 官方已更新 2 年前