带有条件分支的SSM runCommand文档



我正在创建一个aws-ssm文档,在第一步中,我尝试运行shell脚本。

- name: checkMembership
action: 'aws:runCommand'
inputs:
DocumentName: AWS-RunShellScript
InstanceIds:
- '{{InstanceIds}}'
Parameters:
commands:
- mkdir testFolder

我的问题是,如果在这里使用powershell脚本或shell脚本,我是否能够执行多行操作?

- name: checkMembership
action: 'aws:runCommand'
inputs:
DocumentName: AWS-RunShellScript
InstanceIds:
- '{{InstanceIds}}'
Parameters:
commands:
- if $foo
- then
- echo 'hello'
- else
- echo 'bye'

是的,您可以在命令中使用条件分支。

这里有一个例子:

"runCommand": [
"#!/bin/bash",
"example_var=true",
"   if [ "$example_var" = true ] ;",
"   then",
"     echo "example_var is true"",
"   else",
"     echo "example_var is not true"",
"   fi"
]

我建议您查看AWS管理的文档。这里有一些非常好的例子,你可以参考。

最新更新