使用Amazon EC2 Simple Systems Manager,您可以配置 SSM 文档以在实例上运行脚本,并向该脚本传递参数。 Lambda 实例需要运行 SSM 发送命令,通过实例 ID 定位实例。
示例 SSM 文档:
run_my_example.json:
{
"schemaVersion": "1.2",
"description": "Run shell script to launch.",
"parameters": {
"taskId":{
"type":"String",
"default":"",
"description":"(Required) the Id of the task to run",
"maxChars":16
}
},
"runtimeConfig": {
"aws:runShellScript": {
"properties": [
{
"id": "0.aws:runShellScript",
"runCommand": ["run_my_example.sh"]
}
]
}
}
}
上面的SSM文档接受taskId作为参数。
将此文档保存为 JSON 文件,并使用 AWS CLI 调用 create-document:
aws ssm create-document --content file:///tmp/run_my_example.json --name "run_my_example"
您可以致电describe-document查看SSM文档的描述:
aws ssm describe-document --name "run_my_example"
您可以指定taskId参数并使用带有send-command的文档名称运行命令
aws ssm send-command --instance-ids i-12345678 --document-name "run_my_example" --parameters --taskid=123456
注意事项