

# Tagging repositories in AWS CodeCommit
Tagging a repository

A *tag* is a custom attribute label that you or AWS assigns to an AWS resource. AWS tags are different from Git tags, which can be applied to commits. Each AWS tag has two parts:
+ A *tag key* (for example, `CostCenter`, `Environment`, `Project`, or `Secret`). Tag keys are case sensitive.
+ An optional field known as a *tag value* (for example, `111122223333`, `Production`, or a team name). Omitting the tag value is the same as using an empty string. Like tag keys, tag values are case sensitive.

Together these are known as key-value pairs. For limits on the number of tags you can have on a repository and restrictions on tag keys and values, see [Limits](limits.md#limits-tags).

Tags help you identify and organize your AWS resources. Many AWS services support tagging, so you can assign the same tag to resources from different services to indicate that the resources are related. For example, you can assign the same tag to a CodeCommit repository that you assign to an Amazon S3 bucket. For more information about tagging strategies, see [Tagging AWS Resources](https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html). 

In CodeCommit, the primary resource is a repository. You can use the CodeCommit console, the AWS CLI, CodeCommit APIs, or AWS SDKs to add, manage, and remove tags for a repository. In addition to identifying, organizing, and tracking your repository with tags, you can use tags in IAM policies to help control who can view and interact with your repository. For examples of tag-based access policies, see [Example 5: Deny or allow actions on repositories with tags](customer-managed-policies.md#identity-based-policies-example-5).

**Topics**
+ [

# Add a tag to a repository
](how-to-tag-repository-add.md)
+ [

# View tags for a repository
](how-to-tag-repository-list.md)
+ [

# Edit tags for a repository
](how-to-tag-repository-update.md)
+ [

# Remove a tag from a repository
](how-to-tag-repository-delete.md)

# Add a tag to a repository


Adding tags to a repository can help you identify and organize your AWS resources and manage access to them. First, you add one or more tags (key-value pairs) to a repository. Keep in mind that there are limits on the number of tags you can have on a repository. There are restrictions on the characters you can use in the key and value fields. For more information, see [Limits](limits.md#limits-tags). After you have tags, you can create IAM policies to manage access to the repository based on these tags. You can use the the CodeCommit console or the AWS CLI to add tags to a repository. 

**Important**  
Adding tags to a repository can impact access to that repository. Before you add a tag to a repository, make sure to review any IAM policies that might use tags to control access to resources such as repositories. For examples of tag-based access policies, see [Example 5: Deny or allow actions on repositories with tags](customer-managed-policies.md#identity-based-policies-example-5).

For more information about adding tags to a repository when you create it, see [Create a repository (console)](how-to-create-repository.md#how-to-create-repository-console).

**Topics**
+ [

## Add a tag to a repository (console)
](#how-to-tag-repository-add-console)
+ [

## Add a tag to a repository (AWS CLI)
](#how-to-tag-repository-add-cli)

## Add a tag to a repository (console)


You can use the CodeCommit console to add one or more tags to a CodeCommit repository. 

1. Open the CodeCommit console at [https://console.aws.amazon.com/codesuite/codecommit/home](https://console.aws.amazon.com/codesuite/codecommit/home).

1. In **Repositories**, choose the name of the repository where you want to add tags.

1. In the navigation pane, choose **Settings**. Choose **Repository tags**.

1. If no tags have been added to the repository, choose **Add tag**. Otherwise, choose **Edit**, and then choose **Add tag**.

1. In **Key**, enter a name for the tag. You can add an optional value for the tag in **Value**.   
![\[Adding a tag to a repository\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-repository-tags-edit.png)

1. (Optional) To add another tag, choose **Add tag** again.

1. When you have finished adding tags, choose **Submit**.

## Add a tag to a repository (AWS CLI)


Follow these steps to use the AWS CLI to add a tag to a CodeCommit repository. To add a tag to a repository when you create it, see [Create a repository (AWS CLI)](how-to-create-repository.md#how-to-create-repository-cli).

In these steps, we assume that you have already installed a recent version of the AWS CLI or updated to the current version. For more information, see [Installing the AWS Command Line Interface](https://docs.aws.amazon.com/cli/latest/userguide/installing.html).

At the terminal or command line, run the **tag-resource** command, specifying the Amazon Resource Name (ARN) of the repository where you want to add tags and the key and value of the tag you want to add. You can add more than one tag to a repository. For example, to tag a repository named *MyDemoRepo* with two tags, a tag key named *Status* with the tag value of *Secret*, and a tag key named *Team* with the tag value of *Saanvi*:

```
aws codecommit tag-resource --resource-arn arn:aws:codecommit:us-west-2:111111111111:MyDemoRepo --tags Status=Secret,Team=Saanvi 
```

If successful, this command returns nothing.

# View tags for a repository


Tags can help you identify and organize your AWS resources and manage access to them. For more information about tagging strategies, see [Tagging AWS Resources](https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html). For examples of tag-based access policies, see [Example 5: Deny or allow actions on repositories with tags](customer-managed-policies.md#identity-based-policies-example-5).

## View tags for a repository (console)


You can use the CodeCommit console to view the tags associated with a CodeCommit repository. 

1. Open the CodeCommit console at [https://console.aws.amazon.com/codesuite/codecommit/home](https://console.aws.amazon.com/codesuite/codecommit/home).

1. In **Repositories**, choose the name of the repository where you want to view tags.

1. In the navigation pane, choose **Settings**. Choose **Repository tags**.   
![\[Viewing tags for a repository\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-repository-tags-view.png)

## View tags for a repository (AWS CLI)


Follow these steps to use the AWS CLI to view the AWS tags for a CodeCommit repository. If no tags have been added, the returned list is empty.

At the terminal or command line, run the **list-tags-for-resource** command. For example, to view a list of tag keys and tag values for a repository named *MyDemoRepo* with the ARN *arn:aws:codecommit:us-east-2:111111111111:MyDemoRepo*:

```
aws codecommit list-tags-for-resource --resource-arn arn:aws:codecommit:us-west-2:111111111111:MyDemoRepo
```

If successful, this command returns information similar to the following:

```
{
    "tags": {
        "Status": "Secret",
        "Team": "Saanvi"
    }
}
```

# Edit tags for a repository


You can change the value for a tag associated with a repository. You can also change the name of the key, which is equivalent to removing the current tag and adding a different one with the new name and the same value as the other key. Keep in mind that there are limits on the characters you can use in the key and value fields. For more information, see [Limits](limits.md#limits-tags).

**Important**  
Editing tags for a repository can impact access to that repository. Before you edit the name (key) or value of a tag for a repository, make sure to review any IAM policies that might use the key or value for a tag to control access to resources such as repositories. For examples of tag-based access policies, see [Example 5: Deny or allow actions on repositories with tags](customer-managed-policies.md#identity-based-policies-example-5).

## Edit a tag for a repository (console)


You can use the CodeCommit console to edit the tags associated with a CodeCommit repository. 

1. Open the CodeCommit console at [https://console.aws.amazon.com/codesuite/codecommit/home](https://console.aws.amazon.com/codesuite/codecommit/home).

1. In **Repositories**, choose the name of the repository where you want to edit tags.

1. In the navigation pane, choose **Settings**. Choose **Repository tags**. 

1. Choose **Edit**.

1.   
![\[Editing the value of a tag for a repository\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-repository-tags-edit2.png)

   Do one of the following:
   + To change the tag, enter a new name in **Key**. Changing the name of the tag is the equivalent of removing a tag and adding a new tag with the new key name.
   + To change the value of a tag, enter a new value. If you want to change the value to nothing, delete the current value and leave the field blank.

1. When you have finished editing tags, choose **Submit**.

## Edit tags for a repository (AWS CLI)


Follow these steps to use the AWS CLI to update a tag for a CodeCommit repository. You can change the value for an existing key, or add another key. 

At the terminal or command line, run the **tag-resource** command, specifying the Amazon Resource Name (ARN) of the repository where you want to update a tag and specify the tag key and tag value:

```
aws codecommit tag-resource --resource-arn arn:aws:codecommit:us-west-2:111111111111:MyDemoRepo --tags Team=Li
```

# Remove a tag from a repository


You can remove one or more tags associated with a repository. Removing a tag does not delete the tag from other AWS resources that are associated with that tag.

**Important**  
Removing tags for a repository can impact access to that repository. Before you remove a tag from a repository, make sure to review any IAM policies that might use the key or value for a tag to control access to resources such as repositories. For examples of tag-based access policies, see [Example 5: Deny or allow actions on repositories with tags](customer-managed-policies.md#identity-based-policies-example-5).

## Remove a tag from a repository (console)


You can use the CodeCommit console to remove the association between a tag and a CodeCommit repository. 

1. Open the CodeCommit console at [https://console.aws.amazon.com/codesuite/codecommit/home](https://console.aws.amazon.com/codesuite/codecommit/home).

1. In **Repositories**, choose the name of the repository where you want to remove tags.

1. In the navigation pane, choose **Settings**. Choose **Repository tags**. 

1. Choose **Edit**.

1. Find the tag you want to remove, and then choose **Remove tag**.

1. When you have finished removing tags, choose **Submit**.

## Remove a tag from a repository (AWS CLI)


Follow these steps to use the AWS CLI to remove a tag from a CodeCommit repository. Removing a tag does not delete it, but simply removes the association between the tag and the repository. 

**Note**  
If you delete a CodeCommit repository, all tag associations are removed from the deleted repository. You do not have to remove tags before you delete a repository.

At the terminal or command line, run the **untag-resource** command, specifying the Amazon Resource Name (ARN) of the repository where you want to remove tags and the tag key of the tag you want to remove. For example, to remove a tag on a repository named *MyDemoRepo* with the tag key *Status*:

```
aws codecommit untag-resource --resource-arn arn:aws:codecommit:us-west-2:111111111111:MyDemoRepo --tag-keys Status
```

If successful, this command returns nothing. To verify the tags associated with the repository, run the **list-tags-for-resource** command.