Page updated Jan 16, 2024

Apply tags to generated resources

Tags are labels consisting of key-value pairs that make it easier to manage, search for, and filter resources. Some popular use cases include:

  • Resource organization
  • Cost allocation
  • Operations support
  • Access control
  • Security risk management

You can learn more about how tags work here, as well as read about best practices for tagging here.

Setting up tags in a new project

When running amplify init, a tags.json file is automatically generated in the amplify/backend/ directory, containing predefined tags.

The structure of the file is the following:

1[
2 {
3 "Key": "user:Stack",
4 "Value": "{project-env}"
5 },
6 {
7 "Key": "user:Application",
8 "Value": "{project-name}"
9 }
10]

Note: For projects created before CLI version 4.28.0. Creating a tags.json file under amplify/backend/ directory with the desired tags will ensure tags being applied to existing resources after invoking amplify push.

The tag configuration file is created, when you run "amplify init" and the initial Amplify project resources are deployed. You can optionally also pre-create the amplify/backend/tags.json configuration file before "amplify init". This allows you to tag the initial Amplify project resources with your designated tags as well.

Using predefined variables

There are predefined tags that let you be more specific with information about the current project, while giving you the opportunity of structuring the tags according to what feels right to you.

The 2 predefined tags are the following:

  • {project-env} - Refers to the project environment (e.g., prod, env, etc)
  • {project-name} - Refers to the current project name (e.g., mytestproject)

There are many different cases in which these tag variables can be used. This is an example of how they can be used together and what the output would be:

1[
2 {
3 "Key": "myawesomekey",
4 "Value": "myvalue-{project-name}-{project-env}"
5 }
6]

When getting pushed, the resources would transform into:

1[
2 {
3 "Key": "myawesomekey",
4 "Value": "myvalue-myamplifyproject-dev"
5 }
6]

Tag values are not required, thus they can be empty.

1[
2 {
3 "Key": "MY_TAG_KEY",
4 "Value": ""
5 }
6]

Adding and updating tags

You can update or add any additional tags in the tags.json file inside the amplify/backend/ folder by editing the file itself. The file must in a JSON format and should follow this structure:

1[{
2 "Key": “MY_TAG_KEY”,
3 "Value": “MY_TAG_VALUE"
4}]

To update the AWS resources from your Amplify project just run amplify push.

Restrictions

  • You can only add up to 50 tags to the amplify/backend/tags.json file.
  • Tag keys and values are case sensitive.
  • Duplicate tag keys are not allowed.

For more information on limits and restrictions with tagging conventions, please visit this link.