update_task_protection
async
¶
update_task_protection(
cluster: String,
tasks: StringList,
protection_enabled: Boolean,
*,
config_overrides: Optional[AsyncECSClientConfig] = None,
expires_in_minutes: Optional[BoxedInteger] = None,
) -> UpdateTaskProtectionResponse
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 .
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.
If you prefer to set task protection from within the container, we recommend using the Task scale-in protection endpoint.
Parameters:
-
cluster(String) –The short name or full Amazon Resource Name (ARN) of the cluster that hosts the service that the task sets exist in.
-
tasks(StringList) –A list of up to 10 task IDs or full ARN entries.
-
protection_enabled(Boolean) –Specify
trueto mark a task for protection andfalseto unset protection, making it eligible for termination. -
expires_in_minutes(Optional[BoxedInteger], default:None) –If you set
protectionEnabledtotrue, 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,protectionEnabledwill be reset tofalse.If you don’t specify the time, then the task is automatically protected for 120 minutes (2 hours).
Raises:
-
AccessDeniedException–You don't have authorization to perform the requested action.
-
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.
-
ClusterNotFoundException–The specified cluster wasn't found. You can view your available clusters with ListClusters. Amazon ECS clusters are Region specific.
-
InvalidParameterException–The specified parameter isn't valid. Review the available parameters for the API request.
For more information about service event errors, see Amazon ECS service event messages.
-
ResourceNotFoundException–The specified resource wasn't found.
-
ServerException–These errors are usually caused by a server issue.
-
UnsupportedFeatureException–The specified task isn't supported in this Region.
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
To set task scale-in protection for a task for 60 minutes This example enables scale-in protection for a task for 60 minutes.
>>> await client.update_task_protection(cluster='test-task-protection', tasks=['b8b1cf532d0e46ba8d44a40d1de16772'], protection_enabled=True, expires_in_minutes=60)
To set task scale-in protection for the default time period in minutes
This example enables task scale-in protection for a task, without specifying the expiresInMinutes parameter, for the default protection period of 120 minutes.
>>> await client.update_task_protection(cluster='test-task-protection', tasks=['b8b1cf532d0e46ba8d44a40d1de16772'], protection_enabled=True)
To remove task scale-in protection
This example removes scale-in protection for a task.
>>> await client.update_task_protection(cluster='test-task-protection', tasks=['b8b1cf532d0e46ba8d44a40d1de16772'], protection_enabled=False)
Source code in docs_src/capo_ecs/_services/async_ecs.py
6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 | |