UpdateTaskProtection - Amazon Elastic Container Service
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

UpdateTaskProtection

Updates the protection status of a task. You can set protectionEnabled to true to protect your task from termination during scale-in events from Service Autoscaling or deployments.

Task-protection, by default, expires after 2 hours at which point Amazon ECS clears the protectionEnabled property making the task eligible for termination by a subsequent scale-in event.

You can specify a custom expiration period for task protection from 1 minute to up to 2,880 minutes (48 hours). To specify the custom expiration period, set the expiresInMinutes property. The expiresInMinutes property is always reset when you invoke this operation for a task that already has protectionEnabled set to true. You can keep extending the protection expiration period of a task by invoking this operation repeatedly.

To learn more about Amazon ECS task protection, see Task scale-in protection in the Amazon Elastic Container Service Developer Guide .

Note

This operation is only supported for tasks belonging to an Amazon ECS service. Invoking this operation for a standalone task will result in an TASK_NOT_VALID failure. For more information, see API failure reasons.

Important

If you prefer to set task protection from within the container, we recommend using the Task scale-in protection endpoint.

Request Syntax

{ "cluster": "string", "expiresInMinutes": number, "protectionEnabled": boolean, "tasks": [ "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.

cluster

The short name or full Amazon Resource Name (ARN) of the cluster that hosts the service that the task sets exist in.

Type: String

Required: Yes

expiresInMinutes

If you set protectionEnabled to true, you can specify the duration for task protection in minutes. You can specify a value from 1 minute to up to 2,880 minutes (48 hours). During this time, your task will not be terminated by scale-in events from Service Auto Scaling or deployments. After this time period lapses, protectionEnabled will be reset to false.

If you don’t specify the time, then the task is automatically protected for 120 minutes (2 hours).

Type: Integer

Required: No

protectionEnabled

Specify true to mark a task for protection and false to unset protection, making it eligible for termination.

Type: Boolean

Required: Yes

tasks

A list of up to 10 task IDs or full ARN entries.

Type: Array of strings

Required: Yes

Response Syntax

{ "failures": [ { "arn": "string", "detail": "string", "reason": "string" } ], "protectedTasks": [ { "expirationDate": number, "protectionEnabled": boolean, "taskArn": "string" } ] }

Response Elements

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

The following data is returned in JSON format by the service.

failures

Any failures associated with the call.

Type: Array of Failure objects

protectedTasks

A list of tasks with the following information.

  • taskArn: The task ARN.

  • protectionEnabled: The protection status of the task. If scale-in protection is turned on for a task, the value is true. Otherwise, it is false.

  • expirationDate: The epoch time when protection for the task will expire.

Type: Array of ProtectedTask objects

Errors

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

AccessDeniedException

You don't have authorization to perform the requested action.

HTTP Status Code: 400

ClientException

These errors are usually caused by a client action. This client action might be using an action or resource on behalf of a user that doesn't have permissions to use the action or resource,. Or, it might be specifying an identifier that isn't valid.

HTTP Status Code: 400

ClusterNotFoundException

The specified cluster wasn't found. You can view your available clusters with ListClusters. Amazon ECS clusters are Region specific.

HTTP Status Code: 400

InvalidParameterException

The specified parameter isn't valid. Review the available parameters for the API request.

HTTP Status Code: 400

ResourceNotFoundException

The specified resource wasn't found.

HTTP Status Code: 400

ServerException

These errors are usually caused by a server issue.

HTTP Status Code: 500

UnsupportedFeatureException

The specified task isn't supported in this Region.

HTTP Status Code: 400

Examples

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

You only need to learn how to sign HTTP requests if you intend to create them manually. When you use the Amazon Command Line Interface or one of the Amazon SDKs to make requests to Amazon, 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 1

This example request enables scale-in protection for a task for 60 minutes.

Sample Request

POST / HTTP/1.1 Host: ecs.us-west-2.amazonaws.com Accept-Encoding: identity Content-Length: 132 X-Amz-Target: AmazonEC2ContainerServiceV20141113.UpdateTaskProtection X-Amz-Date: 20221102T184632Z Content-Type: application/x-amz-json-1.1 Authorization: AUTHPARAMS { "cluster": "test-task-protection", "tasks": [ "b8b1cf532d0e46ba8d44a40d1de16772" ], "protectionEnabled": true, "expiresInMinutes": 60 }

Sample Response

HTTP/1.1 200 OK Server: Server Date: Wed, 02 Nov 2022 17:56:32 GMT Content-Type: application/x-amz-json-1.1 Content-Length: 180 Connection: keep-alive x-amzn-RequestId: 123a4b56-7c89-01d2-3ef4-example5678f { "protectedTasks": [ { "taskArn": "arn:aws:ecs:us-west-2:012345678910:task/default/b8b1cf532d0e46ba8d44a40d1de16772", "protectionEnabled": true, "expirationDate": 1667415392.553 } ], "failures": [] }

Example 2

This example request enables scale-in protection for a task without specifying the expiresInMinutes parameter. By default, the task will be protected from scale-in events for 120 minutes.

Sample Request

POST / HTTP/1.1 Host: ecs.us-west-2.amazonaws.com Accept-Encoding: identity Content-Length: 132 X-Amz-Target: AmazonEC2ContainerServiceV20141113.UpdateTaskProtection X-Amz-Date: 20221103T212558Z Content-Type: application/x-amz-json-1.1 Authorization: AUTHPARAMS { "cluster": "test-task-protection", "tasks": [ "b8b1cf532d0e46ba8d44a40d1de16772" ], "protectionEnabled": true }

Sample Response

HTTP/1.1 200 OK Server: Server Date: Thu, 03 Nov 2022 21:25:57 GMT Content-Type: application/x-amz-json-1.1 Content-Length: 180 Connection: keep-alive x-amzn-RequestId: 123a4b56-7c89-01d2-3ef4-example5678f { "protectedTasks": [ { "taskArn": "arn:aws:ecs:us-west-2:012345678910:task/default/b8b1cf532d0e46ba8d44a40d1de16772", "protectionEnabled": true, "expirationDate": 1667517958.355 } ], "failures": [] }

Example 3

This example request turns off scale-in protection for a task.

Sample Request

POST / HTTP/1.1 Host: ecs.us-west-2.amazonaws.com Accept-Encoding: identity Content-Length:109 X-Amz-Target: AmazonEC2ContainerServiceV20141113.UpdateTaskProtection X-Amz-Date: 20221103T213134Z Content-Type: application/x-amz-json-1.1 Authorization: AUTHPARAMS { "cluster": "test-task-protection", "tasks": [ "b8b1cf532d0e46ba8d44a40d1de16772" ], "protectionEnabled":false }

Sample Response

HTTP/1.1 200 OK Server: Server Date: Thu, 03 Nov 2022 21:31:34 GMT Content-Type: application/x-amz-json-1.1 Content-Length: 180 Connection: keep-alive x-amzn-RequestId: 123a4b56-7c89-01d2-3ef4-example5678f { "protectedTasks": [ { "taskArn": "arn:aws:ecs:us-west-2:012345678910:task/default/b8b1cf532d0e46ba8d44a40d1de16772", "protectionEnabled": false } ], "failures": [] }

See Also

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