How to create AMI from existing EC2 instance with tags from AWS CLI?

Viewed 454

I'm trying to create a new AMI from my existing EC2 instance with tags. I tried the following command but it doesn't work:

aws ec2 create-image --instance-id i-xxxxxxxxxxxxx --name "TEST_AMI" --no-reboot --tag-specifications 'ResourceType=instance,Tags=[{Key=name,Value=TEST_AMI}

and its return following error:

**usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:
  aws help
  aws <command> help
  aws <command> <subcommand> help
Unknown options: --tag-specifications, ResourceType=instance,Tags=[{Key=name,Value=TEST_AMI}]**

I just need to do both tasks in one command.

1 Answers

The value for the ResourceType is invalid. From create-image documentation:

The tags to apply to the AMI and snapshots on creation. You can tag the AMI, the snapshots, or both.

  • To tag the AMI, the value for ResourceType must be image.
  • To tag the snapshots that are created of the root volume and of other Amazon EBS volumes that are attached to the instance, the value for ResourceType must be snapshot. The same tag is applied to all of the snapshots that are created.
Related