

# Tagging a private repository in Amazon ECR
<a name="ecr-using-tags"></a>

To help you manage your Amazon ECR repositories, you can assign your own metadata to new or existing Amazon ECR repositories by using AWS resource *tags*. For example, you could define a set of tags for your account's Amazon ECR repositories that helps you track the owner of each repository.

## Tag basics
<a name="tag-basics"></a>

Tags don't have any semantic meaning to Amazon ECR and are interpreted strictly as a string of characters. Tags are not 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, but 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 Amazon ECR console, the AWS CLI, and the Amazon ECR API.

Using AWS Identity and Access Management (IAM), you can control which users in your AWS account have permission to create, edit, or delete tags. For information about tags in IAM policies, see [Using Tag-Based Access Control](ecr-supported-iam-actions-tagging.md).

## Tagging your resources for billing
<a name="tag-resources-for-billing"></a>

The tags you add to your Amazon ECR repositories are helpful when reviewing cost allocation after enabling them in your Cost & Usage Report. For more information, see [Amazon ECR usage reports](usage-reports.md).

To see the cost of your combined resources, you can organize your billing information based on resources that have the same tag key values. For example, you can tag several resources with a specific application name, and then organize your billing information to see the total cost of that application across several services. For more information about setting up a cost allocation report with tags, see [The Monthly Cost Allocation Report](https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/configurecostallocreport.html) in the *AWS Billing User Guide*.

**Note**  
If you've just enabled reporting, data for the current month is available for viewing after 24 hours.

# Adding tags to a private repository in Amazon ECR
<a name="adding-tags-repositories"></a>

You can add tags to a private 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*.

## Adding tags to a repository (AWS Management Console)
<a name="tag-resources-console"></a>

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. In the navigation pane, choose **Repositories**.

1. On the **Repositories** page, select the check box next to the repository you want to tag.

1. From the **Action** menu, select **Repository tags**.

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

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

## Adding tags to a repository (AWS CLI or API)
<a name="tag-resources-api-sdk"></a>

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/cli/latest/reference/ecr/tag-resource.html)
+ API action - [TagResource](https://docs.aws.amazon.com/AmazonECR/latest/APIReference/API_TagResource.html)

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

**Example 1: Tag a repository**  
The following command tags a repository.

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

**Example 2: Tag a repository with multiple tags**  
The following command adds three tags to a repository.

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

**Example 3: List tags for a repository**  
The following command lists the tags associated with a repository.

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

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

```
aws ecr create-repository \
     --repository-name test-repo \
     --tags Key=team,Value=devs
```

# Deleting tags from a private repository in Amazon ECR
<a name="deleting-tags-repositories"></a>

You can delete tags from a private repository.

## To delete a tag from a private repository (AWS Management Console)
<a name="deleting-tags-repositories-console"></a>

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, select the check box next to the repository you want to remove a tag from.

1. From the **Action** menu, select **Repository tags**.

1. On the **Repository tags** page, select **Edit**.

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

## To delete a tag from a private repository (AWS CLI)
<a name="deleting-tags-repositories-cli"></a>

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/untag-resource.html)
+ API action - [UntagResource](https://docs.aws.amazon.com/AmazonECR/latest/APIReference/API_UntagResource.html)

The following example shows how to delete a tag from a repository using the AWS CLI.

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