

# Manage tags on AWS Context resources

You can add tags to AWS Context resources when you create them. You can also add, list, and remove tags on existing resources.

## Resources you can tag
<a name="tagging-supported-resources"></a>

The following table lists the AWS Context resource types that you can tag and their Amazon Resource Name (ARN) formats.


| Resource type | ARN format | 
| --- | --- | 
| Agent Context |  `arn:${Partition}:context:${Region}:${Account}:agent-context/${AgentContextId}`  | 
| Connection |  `arn:${Partition}:context:${Region}:${Account}:connection/${ConnectionId}`  | 
| Curation policy |  `arn:${Partition}:context:${Region}:${Account}:curation-policy/${CurationPolicyId}`  | 
| Ontology |  `arn:${Partition}:context:${Region}:${Account}:ontology/${OntologyId}`  | 
| Ontology induction |  `arn:${Partition}:context:${Region}:${Account}:ontology-induction/${OntologyInductionId}`  | 

You can’t tag [built-in ontologies](ontology-built-in.md) or the tasks and evaluations of an Agent Context. Access to tasks and evaluations is controlled by the tags on their Agent Context. For more information about access to tasks and evaluations, see [Access to tasks, evaluations, and Agent Context data](tagging-access-control.md#tagging-access-tasks-evaluations).

## Tag resources when you create them
<a name="tagging-on-create"></a>

The following operations accept an optional `tags` map, which AWS Context applies to the new resource:
+  [`CreateAgentContext`](https://docs.aws.amazon.com/context/latest/APIReference/API_CreateAgentContext.html) 
+  [`CreateConnection`](https://docs.aws.amazon.com/context/latest/APIReference/API_CreateConnection.html) 
+  [`CreateCurationPolicy`](https://docs.aws.amazon.com/context/latest/APIReference/API_CreateCurationPolicy.html) 
+  [`CreateOntology`](https://docs.aws.amazon.com/context/latest/APIReference/API_CreateOntology.html) 
+  [`StartOntologyInduction`](https://docs.aws.amazon.com/context/latest/APIReference/API_StartOntologyInduction.html) 

An [ontology induction](ontology-induce.md) proposes a draft ontology, so `StartOntologyInduction` accepts one tag map for the induction and one for that ontology:

 `tags`   
Tags for the ontology induction.

 `ontologyTags`   
Tags for the ontology that the induction creates. AWS Context applies these tags when the induction creates the ontology. An induction that fails or is canceled creates no ontology.

In the AWS Command Line Interface (AWS CLI), use the `--tags` option to add tags when you create a resource. For `start-ontology-induction`, use `--tags` for the induction and `--ontology-tags` for the ontology.

## Add, list, and remove tags
<a name="tagging-add-list-remove"></a>

To manage the tags on an existing resource, use the following API operations:
+  [`TagResource`](https://docs.aws.amazon.com/context/latest/APIReference/API_TagResource.html) adds tags to a resource. If a key already exists on the resource, `TagResource` replaces the value of that key.
+  [`UntagResource`](https://docs.aws.amazon.com/context/latest/APIReference/API_UntagResource.html) removes tags from a resource by key.
+  [`ListTagsForResource`](https://docs.aws.amazon.com/context/latest/APIReference/API_ListTagsForResource.html) lists the tags on a resource.

The following examples use the AWS CLI to manage tags on an Agent Context. In these examples, replace `us-east-1`, `111122223333`, and `ac-EXAMPLE11111` with your Region, account ID, and Agent Context ID.

To add tags to a resource, run the `tag-resource` command:

```bash
aws context tag-resource \
    --resource-arn arn:aws:context:us-east-1:111122223333:agent-context/ac-EXAMPLE11111 \
    --tags department=billing,project=alpha
```

To remove tags from a resource, run the `untag-resource` command with the keys to remove:

```bash
aws context untag-resource \
    --resource-arn arn:aws:context:us-east-1:111122223333:agent-context/ac-EXAMPLE11111 \
    --tag-keys project
```

To list the tags on a resource, run the `list-tags-for-resource` command:

```bash
aws context list-tags-for-resource \
    --resource-arn arn:aws:context:us-east-1:111122223333:agent-context/ac-EXAMPLE11111
```

The `list-tags-for-resource` command returns output similar to the following:

```json
{
    "tags": {
        "department": "billing"
    }
}
```

 AWS Context logs `TagResource`, `UntagResource`, and `ListTagsForResource` calls in AWS CloudTrail and records the tags in create requests. For more information, see [Logging AWS Context API calls using AWS CloudTrail](logging-using-cloudtrail.md).

## Tag restrictions
<a name="tagging-restrictions"></a>

The following restrictions apply to tags on AWS Context resources:
+ Each resource can have up to 50 user tags. User tags are tags whose keys don’t start with `aws:`.
+ A tag key must be 1–128 characters long.
+ A tag value must be 0–256 characters long.
+ Tag keys are case-sensitive. For example, `Team` and `team` are different keys.
+  AWS reserves keys that start with `aws:`. You can’t add or remove these tags.
+ Tags must comply with any AWS Organizations tag policies that apply to your account. For more information, see [Tag policies](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_tag-policies.html) in the * AWS Organizations User Guide*.