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:
[ { "Key": "user:Stack", "Value": "{project-env}" }, { "Key": "user:Application", "Value": "{project-name}" }]
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:
[ { "Key": "myawesomekey", "Value": "myvalue-{project-name}-{project-env}" }]
When getting pushed, the resources would transform into:
[ { "Key": "myawesomekey", "Value": "myvalue-myamplifyproject-dev" }]
Tag values are not required, thus they can be empty.
[ { "Key": "MY_TAG_KEY", "Value": "" }]
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:
[{ "Key": “MY_TAG_KEY”, "Value": “MY_TAG_VALUE"}]
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.