Amazon Elastic Container Service
API Reference (API Version 2014-11-13)

TagResource

Associates the specified tags to a resource with the specified resourceArn. If existing tags on a resource are not specified in the request parameters, they are not changed. When a resource is deleted, the tags associated with that resource are deleted as well.

Request Syntax

{ "resourceArn": "string", "tags": [ { "key": "string", "value": "string" } ] }

Request Parameters

For information about the parameters that are common to all actions, see Common Parameters.

The request accepts the following data in JSON format.

resourceArn

The Amazon Resource Name (ARN) of the resource to which to add tags. Currently, the supported resources are Amazon ECS tasks, services, task definitions, clusters, and container instances.

Type: String

Required: Yes

tags

The tags to add to the resource. A tag is an array of key-value pairs. Tag keys can have a maximum character length of 128 characters, and tag values can have a maximum length of 256 characters.

Type: Array of Tag objects

Array Members: Minimum number of 0 items. Maximum number of 50 items.

Required: Yes

Response Elements

If the action is successful, the service sends back an HTTP 200 response with an empty HTTP body.

Errors

For information about the errors that are common to all actions, see Common Errors.

ClientException

These errors are usually caused by a client action, such as using an action or resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying an identifier that is not valid.

HTTP Status Code: 400

ClusterNotFoundException

The specified cluster could not be found. You can view your available clusters with ListClusters. Amazon ECS clusters are Region-specific.

HTTP Status Code: 400

InvalidParameterException

The specified parameter is invalid. Review the available parameters for the API request.

HTTP Status Code: 400

ResourceNotFoundException

The specified resource could not be found.

HTTP Status Code: 400

ServerException

These errors are usually caused by a server issue.

HTTP Status Code: 500

Example

In the following example or examples, the Authorization header contents (AUTHPARAMS) must be replaced with an AWS Signature Version 4 signature. For more information, see Signature Version 4 Signing Process in the AWS General Reference.

You only need to learn how to sign HTTP requests if you intend to create them manually. When you use the AWS Command Line Interface (AWS CLI) or one of the AWS SDKs to make requests to AWS, these tools automatically sign the requests for you, with the access key that you specify when you configure the tools. When you use these tools, you don't have to sign requests yourself.

Example

This example tags the dev cluster with key team and value dev.

Sample Request

POST / HTTP/1.1 Host: ecs.us-west-2.amazonaws.com Accept-Encoding: identity X-Amz-Target: AmazonEC2ContainerServiceV20141113.TagResource Content-Type: application/x-amz-json-1.1 X-Amz-Date: 20181026T194744Z Authorization: AUTHPARAMS Content-Length: 115 { "resourceArn":"arn:aws:ecs:us-west-2:012345678910:cluster/dev", "tags":[ { "key":"team", "value":"dev" } ] }

Sample Response

HTTP/1.1 200 OK x-amzn-RequestId: 123a4b56-7c89-01d2-3ef4-example5678f Content-Type: application/x-amz-json-1.1 Content-Length: 2 Date: Fri, 26 Oct 2018 20:01:34 GMT {}

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: