

# Tagging Amazon Braket resources
<a name="braket-tagging-resources"></a>

A *tag* is a custom attribute label that you assign or that AWS assigns to an AWS resource. A tag is *metadata* that tells more about your resource. Each tag consists of a *key* and a *value*. Together these are known as *key-value pairs*. For tags that you assign, you define the key and value.

In the Amazon Braket console, you can navigate to a quantum task or a notebook and view the list of tags associated with it. You can add a tag, remove a tag, or modify a tag. You can tag a quantum task or notebook upon creation, and then manage associated tags through the console, AWS CLI, or API.

**More about AWS and tags**
+ For general information on tagging, including naming and usage conventions, see [What is Tag Editor?](https://docs.aws.amazon.com/tag-editor/latest/userguide/tagging.html) in the *Tagging AWS Resources and Tag Editor* User Guide.
+ For information about restrictions on tagging, see [Tag naming limits and requirements](https://docs.aws.amazon.com/tag-editor/latest/userguide/best-practices-and-strats.html#id_tags_naming_best_practices) in the *Tagging AWS Resources and Tag Editor* User Guide.
+ For best practices and tagging strategies, see [Best Practices for Tagging AWS Resources](https://docs.aws.amazon.com/whitepapers/latest/tagging-best-practices/tagging-best-practices.html).
+ For a list of services that support using tags, see the [https://docs.aws.amazon.com/resourcegroupstagging/latest/APIReference/overview.html](https://docs.aws.amazon.com/resourcegroupstagging/latest/APIReference/overview.html).

The following sections provide more specific information about tags for Amazon Braket.

**Topics**
+ [

## Using tags
](#tags)
+ [

## Supported resources for tagging in Amazon Braket
](#tag-supported-resources)
+ [

## Tagging with the Amazon Braket API
](#braket-cli-tagging)
+ [

# Tagging restrictions
](tag-restrictions.md)
+ [

# Managing tags in Amazon Braket
](tag-managing.md)
+ [

# Example of AWS CLI tagging in Amazon Braket
](braket-tags-example.md)

## Using tags
<a name="tags"></a>

Tags can organize your resources into categories that are useful to you. For example, you can assign a "Department" tag to specify the department that owns this resource.

Each tag has two parts:
+ A tag key (for example, *CostCenter*, *Environment*, or *Project*). Tag keys are case sensitive.
+ An optional field known as a tag value (for example, *111122223333* or *Production*). Omitting the tag value is the same as using an empty string. Like tag keys, tag values are case sensitive.

Tags help you do the following things:
+  **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.
+  **Track your AWS costs.** You activate these tags on the AWS Billing and Cost Management dashboard. AWS uses the tags to categorize your costs and deliver a monthly cost allocation report to you. For more information, see [Use cost allocation tags](https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/cost-alloc-tags.html) in the [https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/billing-what-is.html](https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/billing-what-is.html).
+  **Control access to your AWS resources.** For more information, see [Controlling access using tags](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_tags.html).

## Supported resources for tagging in Amazon Braket
<a name="tag-supported-resources"></a>

The following resource type in Amazon Braket supports tagging:
+  [https://docs.aws.amazon.com/braket/latest/developerguide/braket-manage-access.html#resources](https://docs.aws.amazon.com/braket/latest/developerguide/braket-manage-access.html#resources) resource
+  **Resource Name:** `AWS::Service::Braket` 
+  **ARN Regex:** `arn:${Partition}:braket:${Region}:${Account}:quantum-task/${RandomId}` 

 **Note:** You can apply and manage tags for your Amazon Braket notebooks in the Amazon Braket console, by using the console to navigate to the notebook resource, although the notebooks actually are Amazon SageMaker AI resources. For more information, see [Notebook Instance Metadata](https://docs.aws.amazon.com/sagemaker/latest/dg/nbi-metadata.html) in the SageMaker documentation.

## Tagging with the Amazon Braket API
<a name="braket-cli-tagging"></a>
+ If you're using the Amazon Braket API to set up tags on a resource, call the [https://docs.aws.amazon.com/braket/latest/APIReference/API_Operations.html](https://docs.aws.amazon.com/braket/latest/APIReference/API_Operations.html).

 `aws braket tag-resource --resource-arn $YOUR_TASK_ARN --tags {\"city\":\"Seattle\"}` 
+ To remove tags from a resource, call the [https://docs.aws.amazon.com/braket/latest/APIReference/API_Operations.html](https://docs.aws.amazon.com/braket/latest/APIReference/API_Operations.html).

 `aws braket list-tags-for-resource --resource-arn $YOUR_TASK_ARN` 
+ To list all tags that are attached to a particular resource, call the [https://docs.aws.amazon.com/braket/latest/APIReference/API_Operations.html](https://docs.aws.amazon.com/braket/latest/APIReference/API_Operations.html).

 `aws braket tag-resource --resource-arn $YOUR_TASK_ARN --tag-keys "[\"city\",\"state\"]"` 

# Tagging restrictions
<a name="tag-restrictions"></a>

The following basic restrictions apply to tags on Amazon Braket resources:
+ Maximum number of tags that you can assign to a resource: 50
+ Maximum key length: 128 Unicode characters
+ Maximum value length: 256 Unicode characters
+ Valid characters for key and value: `a-z, A-Z, 0-9, space`, and these characters: `_ . : / = + -` and `@` 
+ Keys and values are case sensitive.
+ Don't use `aws` as a prefix for keys; it's reserved for AWS use.

# Managing tags in Amazon Braket
<a name="tag-managing"></a>

You set tags as *properties* on a *resource*. You can view, add, modify, list, and delete tags through the Amazon Braket console, the Amazon Braket API, or the AWS CLI. For more information, see the [Amazon Braket API reference](https://docs.aws.amazon.com/braket/latest/APIReference/Welcome.html).

**Topics**
+ [

## Adding tags
](#add-tags)
+ [

## Viewing tags
](#view-tags)
+ [

## Editing tags
](#edit-tags)
+ [

## Removing tags
](#remove-tags)

## Adding tags
<a name="add-tags"></a>

You can add tags to taggable resources at the following times:
+  **When you create the resource:** Use the console, or include the `Tags` parameter with the `Create` operation in the [AWS API](https://docs.aws.amazon.com/braket/latest/APIReference/API_Operations.html).
+  **After you create the resource:** Use the console to navigate to the quantum task or notebook resource, or call the `TagResource` operation in the [AWS API](https://docs.aws.amazon.com/braket/latest/APIReference/API_Operations.html).

To add tags to a resource when you create it, you also need permission to create a resource of the specified type.

## Viewing tags
<a name="view-tags"></a>

You can view the tags on any of the taggable resources in Amazon Braket by using the console to navigate to the task or notebook resource, or by calling the AWS `ListTagsForResource` API operation.

You can use the following AWS API command to view tags on a resource:
+  ** AWS API:** `ListTagsForResource` 

## Editing tags
<a name="edit-tags"></a>

You can edit tags by using the console to navigate to the quantum task or notebook resource or you can use the following command to modify the value for a tag attached to a taggable resource. When you specify a tag key that already exists, the value for that key is overwritten:
+  ** AWS API:** `TagResource` 

## Removing tags
<a name="remove-tags"></a>

You can remove tags from a resource by specifying the keys to remove, by using the console to navigate to the quantum task or notebook resource, or when calling the `UntagResource` operation.
+  ** AWS API:** `UntagResource` 

# Example of AWS CLI tagging in Amazon Braket
<a name="braket-tags-example"></a>

When you are working with the AWS Command Line Interface (AWS CLI) to interact with Amazon Braket, the following code is an example command that demonstrates how to create a tag that applies to a quantum task you create. In this example, the task is being executed on the SV1 quantum simulator with parameter settings specified for the Rigetti quantum processing unit (QPU). It is imporant that inside the example command the tag is specified at the very end, after all of the other required parameters. In this case, the tag has a **Key** of `state` and **Value** of `Washington`. These tags could be used to help categorize or identify this particular quantum task.

```
aws braket create-quantum-task --action /
"{\"braketSchemaHeader\": {\"name\": \"braket.ir.jaqcd.program\", /
    \"version\": \"1\"}, /
    \"instructions\": [{\"angle\": 0.15, \"target\": 0, \"type\": \"rz\"}], /
    \"results\": null, /
    \"basis_rotation_instructions\": null}" /
  --device-arn "arn:aws:braket:::device/quantum-simulator/amazon/sv1" /
  --output-s3-bucket  "my-example-braket-bucket-name" /
  --output-s3-key-prefix "my-example-username"  /
  --shots 100   /
  --device-parameters /
  "{\"braketSchemaHeader\": /
     {\"name\": \"braket.device_schema.rigetti.rigetti_device_parameters\", /
      \"version\": \"1\"}, \"paradigmParameters\": /
       {\"braketSchemaHeader\": /
         {\"name\": \"braket.device_schema.gate_model_parameters\", /
          \"version\": \"1\"}, /
          \"qubitCount\": 2}}" /
          --tags {\"state\":\”Washington\"}
```

This example demonstrates how you can apply tags to your quantum tasks when running them through the AWS CLI, which is helpful for organizing and tracking your Braket resources.