1

While creating EC2 launch templates with the create-launch-template AWS CLI ec2 command and a JSON spec, I can't seem to figure out how to tag the template itself. I'm providing the TagSpecifications correctly, because I can see the tags being applied to the resources when the launch template is used, but I want to tag the template itself, too.

I tried adding a Tags field to the JSON description of the launch template, that gave an error. The docs suggest using a TagSpecification object like so:

{
  "ResourceType": "launch-template",
  "Tags": [
    {
      "Key": "mykey", 
      "Value": "myvalue"
    }
  ]
}

... (note the "launch-template" resource type) which runs just fine without erring, but the template gets created without any tags :-/

I could run some follow-up tagging statements, but I'm trying to avoid doing that, and this article suggests it's doable at creation-time.

1 Answer 1

2

I have followed the AWS-CLI example from Creating a launch template and it was indeed created with the tag associated.

This is the command I used:

aws ec2 create-launch-template \
    --launch-template-name TemplateForWebServer \
    --version-description WebVersion1 \
    --tag-specifications 'ResourceType=launch-template,Tags=[{Key=purpose,Value=production}]' \
    --launch-template-data file://template-data.json

And this is the created launch template:

enter image description here

What's your AWS-CLI version? Perhaps it's too old. Mine is:

~ $ aws --version
aws-cli/1.18.97 Python/3.6.9 Linux/5.4.0-52-generic botocore/1.17.20
3
  • aws-cli/2.0.57 Python/3.9.0 Darwin/19.3.0 source/x86_64 ... but I notice you're providing --tags-specifications separately from --launch-template-data. In my case, I placed by tag specifications in the JSON spec (in the tagSpecifications field, as described in the documentation). I wonder if that's the difference?
    – mmuurr
    Nov 12, 2020 at 16:33
  • @mmuurr it kind of makes sense - the template is the resource you want tagged and the tags are external to that resource, hence it makes sense that they are specified in a separate parameter. Give it a try this way and see if it helps. If it does accept the answer please to tick it off as solved. Thanks
    – MLu
    Nov 13, 2020 at 0:18
  • yeah that worked, though the AWS CLI docs suggest either would work, and it doesn't even make sense that a EC2 Launch Template would tag a downstream EC2 Launch Template, as I don't think(?) they can create 'themselves', but :shrug:. In any case, thanks for the idea!
    – mmuurr
    Nov 20, 2020 at 7:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .