【发布时间】:2020-01-07 11:29:30
【问题描述】:
我有一个 CloudFormation 模板,它创建一组 SSM 命令来管理我的 Linux EC2 实例。此命令必须有权访问我的 AWS 帐号才能执行某些任务。
在我的 CloudFormation 模板上,我做了:
AWSTemplateFormatVersion: '2010-09-09'
Description: Sample SSM commands
MyCommand1:
Type: AWS::SSM::Document
Properties:
DocumentType: Command
Content:
schemaVersion: "2.2"
parameters: {}
mainSteps:
- action: aws:runShellScript
name : command1
inputs:
runCommand:
- echo "this command run on the selected EC2 instance" && echo "You are running this on account {{global:ACCOUNT_ID}}"
Outputs:
Command1ID:
Description: MyCommand1
Value: !Ref MyCommand1
此模板安装功能,我可以从 SSM Web 控制台运行它。
但是 {{global:ACCOUNT_ID}} 对我的帐号不重要。它的值是字符串“{{global:ACCOUNT_ID}}”。所以我认为这不是在 SSM 命令中使用 global var 的好语法。
因此,在阅读此处https://docs.aws.amazon.com/systems-manager/latest/userguide/walkthrough-cli.html 的文档后,我尝试仅通过 CLI 进行测试(以快速测试其他语法):
$> sh_command_id=$(aws ssm send-command --instance-ids "i-0cb0c0ea8ef7339f1" --document-name "AWS-RunShellScript" --parameters commands='echo You are running this on account {{global:ACCOUNT_ID}}' --output text --query "Command.CommandId")
但该命令失败并出现解析错误Error parsing parameter '--parameters': Expected: ',', received: '}' for input
在 SSM“runCommand”操作中使用 {{global:*}} 的正确语法是什么?
【问题讨论】: