在AWS Systems Manager (SSM) 的自动化文档中,无法直接替换变量,但可以通过以下方法解决:
{
"schemaVersion": "0.3",
"description": "Run shell script on EC2 instances",
"parameters": {
"Script": {
"type": "String",
"description": "The shell script to run"
}
},
"mainSteps": [
{
"action": "aws:runShellScript",
"name": "runShellScript",
"inputs": {
"runCommand": [
"{{ Script }}"
]
}
}
]
}
在执行自动化文档时,您可以传递"Script"参数的值,如下所示:
aws ssm start-automation-execution --document-name "MyAutomationDocument" --parameters "Script=echo Hello"
这将执行一个简单的echo命令,输出"Hello"。
aws ssm start-automation-execution --document-name "MyAutomationDocument" --parameters "Script=echo Hello"
您可以在自动化文档中使用{{}}来指示变量,例如:
{
"schemaVersion": "0.3",
"description": "Run shell script on EC2 instances",
"mainSteps": [
{
"action": "aws:runShellScript",
"name": "runShellScript",
"inputs": {
"runCommand": [
"{{ Script }}"
]
}
}
]
}
这将执行一个简单的echo命令,输出"Hello"。
请注意,以上示例仅为演示目的,并不适用于所有情况。在实际应用中,您可能需要根据自己的需求来适应相关代码。
上一篇:AWS-RunShellScript调用python脚本无法找到python模块。
下一篇:AWS-S3 orb - Circle CI - Unexpected argument(s): arguments AWS-S3 orb - Circle CI - 非预期参数: arguments