AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.
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.
For .NET Core this operation is only available in asynchronous form. Please refer to UpdateTaskProtectionAsync.
Namespace: Amazon.ECS
Assembly: AWSSDK.ECS.dll
Version: 3.x.y.z
public virtual UpdateTaskProtectionResponse UpdateTaskProtection( UpdateTaskProtectionRequest request )
Container for the necessary parameters to execute the UpdateTaskProtection service method.
| Exception | Condition |
|---|---|
| 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. |
This example enables scale-in protection for a task for 60 minutes.
var client = new AmazonECSClient();
var response = client.ContinueServiceDeployment(new ContinueServiceDeploymentRequest
{
Action = "CONTINUE",
HookId = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
ServiceDeploymentArn = "arn:aws:ecs:us-east-1:123456789012:service-deployment/MyCluster/MyService/r9i43YFjvgF_xlg7m2eJ1r"
});
string serviceDeploymentArn = response.ServiceDeploymentArn;
This example enables task scale-in protection for a task, without specifying the expiresInMinutes parameter, for the default protection period of 120 minutes.
var client = new AmazonECSClient();
var response = client.ContinueServiceDeployment(new ContinueServiceDeploymentRequest
{
Action = "ROLLBACK",
HookId = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
ServiceDeploymentArn = "arn:aws:ecs:us-east-1:123456789012:service-deployment/MyCluster/MyService/r9i43YFjvgF_xlg7m2eJ1r"
});
string serviceDeploymentArn = response.ServiceDeploymentArn;
This example removes scale-in protection for a task.
var client = new AmazonECSClient();
var response = client.CreateService(new CreateServiceRequest
{
DeploymentConfiguration = new DeploymentConfiguration {
LifecycleHooks = new List<DeploymentLifecycleHook> {
new DeploymentLifecycleHook {
LifecycleStages = new List<string> {
"POST_PRODUCTION_TRAFFIC_SHIFT"
},
TargetType = "PAUSE",
TimeoutConfiguration = new DeploymentLifecycleHookTimeoutConfiguration {
Action = "ROLLBACK",
TimeoutInMinutes = 60
}
}
},
Strategy = "BLUE_GREEN"
},
DesiredCount = 2,
ServiceName = "ecs-service-with-pause-hook",
TaskDefinition = "ecs-demo"
});
Service service = response.Service;
.NET Framework:
Supported in: 4.7.2 and newer