Tags represent metadata for your AWS resources. Tags are used to separate your AWS resources from one another. These are key/value pairs. If we use good tags, then it's easy to filter resources by tag names. It is also helpful for analyzing your bill; we can get the billing information of all tags by filtering on tags associated with the AWS resources. For example, you can tag several resources with a specific application name, and then organize your billing information to see the total cost for that application across several AWS services. If we add a tag that has the same key as an existing tag, then the new value will override the old value. You can edit tag keys and values at any time, and you can also remove them at any time.
In this recipe, we describe the command for creating tags for our AWS resources.
Using the create-tags
command, you can create tags for one or more AWS resources.
By running the following command, you can create or update one or more tags for one or more AWS resources:
$ aws ec2 create-tags --resources [Resources] --tags [Tags]
The parameters used in this command are described as follows:
[Resources]
: This parameter is used to provide the IDs of one or more resources to tag[Tags]
: This parameter provides a list of tagsSyntax:
Key=KeyName,Value=ValueToAssign
The following command creates the Name
and Group
tag with its associated value for the EC2 instance (i-2e7dace3
):
$ aws ec2 create-tags --resources i-2e7dace3 --tags Key=Name,Value=Tomcat Key=Group,Value='FronEnd Server Group'