1

我正在尝试使用 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"
  }
}

因为运行该过程抱怨我使用“字符串”类型并说我应该使用“地图列表”。

'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.
4

1 回答 1

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 }}"
      }
    }
  ]
}
于 2017-06-17T00:50:21.927 回答