1

I'm trying to use the Amazon EC2 Systems Manager (http://docs.aws.amazon.com/systems-manager/latest/userguide/what-is-systems-manager.html) to create an "Automation" document type to (amongst other things) tag an AMI it just created.

You can create tags in a predetermined manner like this within "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 }}"
      }
    ]
  }
},
...

but to tag with a variable number of Tags, I'm assuming the following change is neccessary:

...
{
  "name": "CreateTags",
  "action": "aws:createTags",
  "maxAttempts": 3,
  "onFailure": "Abort",
  "inputs": {
    "ResourceType": "EC2",
    "ResourceIds": ["{{ CreateImage.ImageId }}"],
    "Tags": {{ Tags }}
  }
},
...

with the addition of a new parameter called 'Tags' of type 'MapList':

"parameters": {
  "Tags": {
    "type": "MapList"
  }
}

since running the process was complaining about my using a 'String' type and saying I should use a 'MapList'.

'MapList' is listed as a parameter type of the Amazon EC2 Systems Manager (http://docs.aws.amazon.com/systems-manager/latest/APIReference/top-level.html), but I have not yet found any documentation on how to define this type.

I have guessed at several formats based upon both what I've seen from their 'hardcoded' sample above and other tagging method in their other API's to no avail:

[ { "Key": "Name", "Value": "newAmi" } ]
[ { "Key": "Name", "Values": [ "newAmi" ] } ]
1: { "Key": "Name", "Values": [ "newAmi" ] }

Does anyone know how to define the new parameter types introduced with the Amazon EC2 Systems Manager (specifically, 'MapList')?

Update:

Since the docs are lacking, Amazon Support is asking the automation team how to best tag ami's using this method. I have found how to add a single tag as a parameter value in the console, though:

{ "Key": "TagName", "Value": "TagValue" }

My attempts to add multiple tags will allow the automation to start:

{ "Key": "TagName1", "Value": "TagValue1" }, { "Key": "TagName2", "Value": "TagValue2" }

but ultimately returns this generic error at runtime:

Internal Server Error. Please refer to Automation Service Troubleshooting 
Guide for more diagnosis details

It might seem like the [] is missing from around the array, but you seem to get those for free because when I add them I get this error:

Parameter type error. [[ { "Key": "Description", "Value": "Desc" }, 
{ "Key": "Name", "Value": "Nm" } ]] is defined as MapList.
Jonathan Grubb
  • 449
  • 3
  • 16

1 Answers1

0

Thanks for using EC2 Systems Manager, Automation feature. Here's the document I tested, it works.

{
  "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 }}"
      }
    }
  ]
}
Cooper.Wu
  • 4,335
  • 8
  • 34
  • 42
  • Thanks @Cooper.Wu. Example does work as is, providing I change assumeRole/ResourceIds and run from the CLI, but this does not work in the console, and complains about the default value for tags: `Parameter type error. [[{"Key":"TagName1","Value":"TagValue1"},{"Key":"TagName2","Value":"TagValue2"}]] is defined as MapList.` More importantly, if I do enter my own values for Tag in the CLI w/o the surrounding "[]"s (errors mentioned in question) it will still fail at runtime: `Internal Server Error. Please refer to Automation Service Troubleshooting Guide for more diagnosis details`. Any advice? – Jonathan Grubb Jun 19 '17 at 22:47