我正在尝试使用Amazon EC2 Systems Manager(http://docs.aws.amazon.com/systems-manager/latest/userguide/what-is-systems-manager.html)来创建“自动化”文档类型,以便(除其他事项外)标记它刚刚创建的AMI。
您可以在“mainSteps”中以预定方式创建标签:
...
{
"name": "CreateTags",
"action": "aws:createTags",
"maxAttempts": 3,
"onFailure": "Abort",
"inputs": {
"ResourceType": "EC2",
"ResourceIds": ["{{ CreateImage.ImageId }}"],
"Tags": [
{
"Key": "Original_AMI_ID",
"Value": "Created from {{ SourceAmiId }}"
}
]
}
},
...
但要使用可变数量的标签进行标记,我假设需要进行以下更改:
...
{
"name": "CreateTags",
"action": "aws:createTags",
"maxAttempts": 3,
"onFailure": "Abort",
"inputs": {
"ResourceType": "EC2",
"ResourceIds": ["{{ CreateImage.ImageId }}"],
"Tags": {{ Tags }}
}
},
...
添加了一个名为'MapList'类型的'Tags'的新参数:
"parameters": {
"Tags": {
"type": "MapList"
}
}
因为运行该进程是抱怨我使用'String'类型并说我应该使用'MapList'。
'MapList'被列为Amazon EC2 Systems Manager(http://docs.aws.amazon.com/systems-manager/latest/APIReference/top-level.html)的参数类型,但我还没有找到有关如何定义此类型的任何文档。
我已经猜到了几种格式,基于我们从上面的“硬编码”示例中看到的内容以及其他API中的其他标记方法都无济于事:
[ { "Key": "Name", "Value": "newAmi" } ]
[ { "Key": "Name", "Values": [ "newAmi" ] } ]
1: { "Key": "Name", "Values": [ "newAmi" ] }
有谁知道如何定义Amazon EC2 Systems Manager(特别是'MapList')引入的新参数类型?
更新
由于缺乏文档,亚马逊支持部门要求自动化团队如何使用此方法最好地标记ami。我已经找到了如何在控制台中添加单个标记作为参数值:
{ "Key": "TagName", "Value": "TagValue" }
我尝试添加多个标签将允许自动启动:
{ "Key": "TagName1", "Value": "TagValue1" }, { "Key": "TagName2", "Value": "TagValue2" }
但最终在运行时返回此一般错误:
Internal Server Error. Please refer to Automation Service Troubleshooting
Guide for more diagnosis details
似乎数组周围缺少[],但你似乎是免费获得这些,因为当我添加它们时我得到了这个错误:
Parameter type error. [[ { "Key": "Description", "Value": "Desc" },
{ "Key": "Name", "Value": "Nm" } ]] is defined as MapList.
答案 0 :(得分:0)
感谢您使用EC2 Systems Manager,自动化功能。这是我测试的文件,它有效。
{
"schemaVersion": "0.3",
"description": "Test tags.",
"assumeRole": "arn:aws:iam::123456789012:role/TestRole",
"parameters": {
"Tags": {
"default": [{
"Key": "TagName1",
"Value": "TagValue1"
},
{
"Key": "TagName2",
"Value": "TagValue2"
}],
"type": "MapList"
}
},
"mainSteps": [
{
"name": "CreateTags",
"action": "aws:createTags",
"maxAttempts": 3,
"onFailure": "Abort",
"inputs": {
"ResourceType": "EC2",
"ResourceIds": [
"i-12345678"
],
"Tags": "{{ Tags }}"
}
}
]
}