

# Tag an Amazon ECR Public repository
Tag a public repository

To help you manage your Amazon ECR Public repositories, you can optionally assign your own metadata to each repository by using *tags*. This topic provides an overview about tags and how to create them.

## Tag basics


A tag is a label that you assign to an AWS resource. Each tag consists of a *key* and an optional *value*. You define both of them.

You can use tags to categorize your AWS resources in different ways, for example, by purpose, owner, or environment. This is useful when you have many resources of the same type. This is because you can quickly identify a specific resource based on the tags you've assigned to it. For example, you can define a set of tags for your account's Amazon ECR Public repositories to track each repository's owner.

We recommend that you devise a set of tag keys that meets your specific needs. Using a consistent set of tag keys can help you keep better track of your resources and find specific resources quickly. That is, you can search and filter the resources based on the specific tags that you add.

Tags don't have any semantic meaning to Amazon ECR and are interpreted strictly as a string of characters. Tags aren't automatically assigned to your resources. You can edit tag keys and values, and you can remove tags from a resource at any time. You can set the value of a tag to an empty string. However, you can't set the value of a tag to null. If you add a tag that has the same key as an existing tag on that resource, the new value overwrites the old value. If you delete a resource, any tags for the resource are also deleted.

You can work with tags using the AWS Management Console, the AWS CLI, and the Amazon ECR Public API.

If you're using AWS Identity and Access Management (IAM), you can control which users in your AWS account have permission to manage tags.

## Tagging your resources


You can tag new or existing Amazon ECR Public repositories.

If you're using the Amazon ECR console, you can apply tags to new resources when they're created or to existing resources by using the **Tags** option on the navigation pane at any time.

If you're using the Amazon ECR Public API, the AWS CLI, or an AWS SDK, you can apply tags to new repositories using the `tags` parameter on the `CreateRepository` API action or use the `TagResource` API action to apply tags to existing resources. For more information, see [TagResource](https://docs.aws.amazon.com/AmazonECRPublic/latest/APIReference/API_TagResource.html).

Additionally, if tags can't be applied when a repository is created, the repository creation process is rolled back. This ensures that repositories are either created with tags or not created at all and that no repositories are left untagged at any time. By tagging repositories when they're created, you eliminate the need to run custom tagging scripts after the repository is created.

# Adding tags to a public repository in Amazon ECR public
Adding tags

You can add tags to a public repository.

For information about names and best practices for tags, see [Tag naming limits and requirements](https://docs.aws.amazon.com//tag-editor/latest/userguide/tagging.html#tag-conventions) and [Best practices](https://docs.aws.amazon.com//tag-editor/latest/userguide/tagging.html#tag-best-practices) in the *Tagging AWS Resources User Guide*.

When you select a specific repository in the Amazon ECR console, you can view the tags by selecting **Tags** in the navigation pane.

------
#### [ AWS Management Console ]

**To add a tag to a public repository**

1. Open the Amazon ECR console at [https://console.aws.amazon.com/ecr/](https://console.aws.amazon.com/ecr/).

1. From the navigation bar, select the AWS Region to use.

1. In the navigation pane, choose **Repositories**.

1. On the **Repositories** page, on the **Public** tab, choose the repository to view.

1. On the **Repositories > *repository\$1name*** page, select **Tags** from the navigation pane.

1. On the **Tags** page, select **Add tags**, **Add tag**.

1. On the **Edit Tags** page, specify the key and value for each tag, and then choose **Save**.

------
#### [ AWS CLI ]

You can add or overwrite one or more tags by using the AWS CLI or an API.
+ AWS CLI - [tag-resource](https://docs.aws.amazon.com/AmazonECRPublic/latest/APIReference/API_TagResource.html)
+ API action - [TagResource](https://docs.aws.amazon.com/AmazonECRPublic/latest/APIReference/API_UntagResource.html)

The following examples show how to manage tags using the AWS CLI.

**Example 1: Tag an existing public repository**  
The following command tags an existing public repository.

```
aws ecr-public tag-resource \
      --resource-arn arn:aws:ecr-public::account_id:repository/repository_name \
      --tags Key=stack,Value=dev \
      --region us-east-1
```

**Example 2: Tag an existing public repository with multiple tags**  
The following command tags an existing repository.

```
aws ecr-public tag-resource \
      --resource-arn arn:aws:ecr-public::account_id:repository/repository_name \
      --tags Key=key1,Value=value1 Key=key2,Value=value2 Key=key3,Value=value3 \
      --region us-east-1
```

**Example 3: List tags for a public repository**  
The following command lists the tags that are associated with an existing public repository.

```
aws ecr-public list-tags-for-resource \
      --resource-arn arn:aws:ecr-public::account_id:repository/repository_name \
      --region us-east-1
```

**Example 4: Create a public repository and apply a tag**  
The following command creates a public repository that's named `test-repo` and adds a tag with key `team` and value `devs`.

```
aws ecr-public create-repository \
      --repository-name test-repo \
      --tags Key=team,Value=devs \
      --region us-east-1
```

------

# Deleting tags from a public repository in Amazon ECR public
Deleting tags

You can delete tags from an individual resource.

------
#### [ AWS Management Console ]

1. Open the Amazon ECR console at [https://console.aws.amazon.com/ecr/](https://console.aws.amazon.com/ecr/).

1. From the navigation bar, select the Region to use.

1. On the **Repositories** page, on the **Public** tab, choose the repository to view.

1. On the **Repositories > *repository\$1name*** page, select **Tags** from the navigation pane.

1. On the **Tags** page, select **Edit**.

1. On the **Edit tags** page, select **Remove** for each tag you want to delete, and choose **Save**.

------
#### [  AWS CLI ]

You can delete one or more tags by using the AWS CLI or an API.
+ AWS CLI - [untag-resource](https://docs.aws.amazon.com/cli/latest/reference/ecr-public/untag-resource.html)
+ API action - [UntagResource](https://docs.aws.amazon.com/AmazonECRPublic/latest/APIReference/API_UntagResource.html)

The following example shows how to delete a tag from an existing public repository.

```
aws ecr-public untag-resource \
      --resource-arn arn:aws:ecr-public::account_id:repository/repository_name \
      --tag-keys tag_key \
      --region us-east-1
```

------