Add and remove tags for Amazon EC2 resources - Amazon Elastic Compute Cloud

Add and remove tags for Amazon EC2 resources

When you create an Amazon EC2 resource, such as an Amazon EC2 instance, you can specify the tags to add to the resource. You can also use the Amazon EC2 console to display the tags for a specific Amazon EC2 resource. You can also add or remove tags from an existing Amazon EC2 resource.

You can use the Tag Editor in the AWS Resource Groups console to view, add, or remove tags across of all of your AWS resources across all Regions. You can apply or remove tags from multiple types of resources at the same time. For more information, see the Tagging AWS Resources User Guide.

Add and remove tags using the console

You can manage tags for an existing resource directly from the resource's page.

To manage tags for an existing resource
  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. From the navigation bar, select the Region where the resource is located.

  3. In the navigation pane, select a resource type (for example, Instances).

  4. Select the resource from the list.

  5. From the Tags tab, choose Manage tags.

  6. To add a tag, choose Add new tag and enter a key and a value for the tag. To remove a tag, choose Remove.

  7. Choose Save.

Add tags using the AWS CLI

The following examples demonstrate how to add tags to an existing resource using the create-tags command.

Example: Add a tag to a resource

The following command adds the tag Stack=production to the specified image, or overwrites an existing tag for the AMI where the tag key is Stack. If the command succeeds, no output is returned.

aws ec2 create-tags \ --resources ami-78a54011 \ --tags Key=Stack,Value=production
Example: Add tags to multiple resources

This example adds (or overwrites) two tags for an AMI and an instance. One of the tags contains just a key (webserver), with no value (we set the value to an empty string). The other tag consists of a key (stack) and value (Production). If the command succeeds, no output is returned.

aws ec2 create-tags \ --resources ami-1a2b3c4d i-1234567890abcdef0 \ --tags Key=webserver,Value= Key=stack,Value=Production
Example: Add tags with special characters

This example adds the tag [Group]=test to an instance. The square brackets ([ and ]) are special characters, which must be escaped.

If you are using Linux or OS X, to escape the special characters, enclose the element with the special character with double quotes ("), and then enclose the entire key and value structure with single quotes (').

aws ec2 create-tags \ --resources i-1234567890abcdef0 \ --tags 'Key="[Group]",Value=test'

If you are using Windows, to escape the special characters, enclose the element that has special characters with double quotes ("), and then precede each double quote character with a backslash (\) as follows:

aws ec2 create-tags ^ --resources i-1234567890abcdef0 ^ --tags Key=\"[Group]\",Value=test

If you are using Windows PowerShell, to escape the special characters, enclose the value that has special characters with double quotes ("), precede each double quote character with a backslash (\), and then enclose the entire key and value structure with single quotes (') as follows:

aws ec2 create-tags ` --resources i-1234567890abcdef0 ` --tags 'Key=\"[Group]\",Value=test'

Add tags using CloudFormation

With Amazon EC2 resource types, you specify tags using either a Tags or TagSpecifications property.

The following examples add the tag Stack=Production to AWS::EC2::Instance using its Tags property.

Example: Tags in YAML
Tags: - Key: "Stack" Value: "Production"
Example: Tags in JSON
"Tags": [ { "Key": "Stack", "Value": "Production" } ]

The following examples add the tag Stack=Production to AWS::EC2::LaunchTemplate LaunchTemplateData using its TagSpecifications property.

Example: TagSpecifications in YAML
TagSpecifications: - ResourceType: "instance" Tags: - Key: "Stack" Value: "Production"
Example: TagSpecifications in JSON
"TagSpecifications": [ { "ResourceType": "instance", "Tags": [ { "Key": "Stack", "Value": "Production" } ] } ]