update_task_protection
¶
update_task_protection(
cluster: String,
tasks: StringList,
protection_enabled: Boolean,
*,
config_overrides: Optional[ECSClientConfig] = 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.
>>> 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.
>>> 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.
>>> client.update_task_protection(cluster='test-task-protection', tasks=['b8b1cf532d0e46ba8d44a40d1de16772'], protection_enabled=False)
Source code in docs_src/capo_ecs/_services/ecs.py
6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 | |