When a deployment starts, it goes through lifecycle stages. These stages can be in states such as IN_PROGRESS or successful. You can use lifecycle hooks, which are Lambda functions that Amazon ECS runs on your behalf at specified lifecycle stages. The functions can be either of the following:
An asynchronous API which validates the health check within 15 minutes.
A poll API which initiates another asynchronous process which evaluates the lifecycle hook completion.
After the function has finished running, it must return a hookStatus
for the deployment to continue. If a hookStatus
is not returned, or if the function fails, the deployment rolls back. The following are the hookStatus
values:
SUCCEEDED
- the deployment continues to the next lifecycle stage
FAILED
â the deployment rolls back to the last successful deployment.
IN_PROGRESS
â Amazon ECS runs the function again after a short period of time. By default this is a 30 second interval, however this value is customizable by returning a callBackDelay
alongside the hookStatus
.
The following example shows how to return a hookStatus
with a custom callback delay. In this example, Amazon ECS would retry this hook in 60 seconds instead of the default 30 seconds:
{
"hookStatus": "IN_PROGRESS",
"callBackDelay": 60
}
When a roll back happens, Amazon ECS runs the lifecycle hooks for the following lifecycle stages:
PRODUCTION_TRAFFIC_SHIFT
TEST_TRAFFIC_SHIFT
When you configure lifecycle hooks for your ECS service deployments, Amazon ECS invokes these hooks at specific stages of the deployment process. Each lifecycle stage provides a JSON payload with information about the current state of the deployment. This document describes the payload structure for each lifecycle stage.
Common payload structureAll lifecycle stage payloads include the following common fields:
serviceArn
- The Amazon Resource Name (ARN) of the service.
targetServiceRevisionArn
- The ARN of the target service revision being deployed.
testTrafficWeights
- A map of service revision ARNs to their corresponding test traffic weight percentages.
productionTrafficWeights
- A map of service revision ARNs to their corresponding production traffic weight percentages.
This stage occurs at the beginning of the deployment process when the service is being reconciled. The following shows an example payload for this lifecycle stage.
{
"serviceArn": "arn:aws:ecs:us-west-2:1234567890:service/myCluster/myService",
"targetServiceRevisionArn": "arn:aws:ecs:us-west-2:1234567890:service-revision/myCluster/myService/01275892",
"testTrafficWeights": {
"arn:aws:ecs:us-west-2:1234567890:service-revision/myCluster/myService/01275892": 100,
"arn:aws:ecs:us-west-2:1234567890:service-revision/myCluster/myService/78652123": 0
},
"productionTrafficWeights": {
"arn:aws:ecs:us-west-2:1234567890:service-revision/myCluster/myService/01275892": 100,
"arn:aws:ecs:us-west-2:1234567890:service-revision/myCluster/myService/78652123": 0
}
}
Expectations at this stage:
Primary task set is at 0% scale
This stage occurs before the new tasks are scaled up. The following shows an example payload for this lifecycle stage.
{
"serviceArn": "arn:aws:ecs:us-west-2:1234567890:service/myCluster/myService",
"targetServiceRevisionArn": "arn:aws:ecs:us-west-2:1234567890:service-revision/myCluster/myService/01275892",
"testTrafficWeights": {},
"productionTrafficWeights": {}
}
Expectations at this stage:
The green service revision tasks are at 0% scale
This stage occurs after the new tasks have been scaled up and are healthy. The following shows an example payload for this lifecycle stage.
{
"serviceArn": "arn:aws:ecs:us-west-2:1234567890:service/myCluster/myService",
"targetServiceRevisionArn": "arn:aws:ecs:us-west-2:1234567890:service-revision/myCluster/myService/01275892",
"testTrafficWeights": {},
"productionTrafficWeights": {}
}
Expectations at this stage:
The green service revision tasks are at 100% scale
Tasks in the green service revision are healthy
This stage occurs when test traffic is being shifted to the green service revision tasks.
The following shows an example payload for this lifecycle stage.
{
"serviceArn": "arn:aws:ecs:us-west-2:1234567890:service/myCluster/myService",
"targetServiceRevisionArn": "arn:aws:ecs:us-west-2:1234567890:service-revision/myCluster/myService/01275892",
"testTrafficWeights": {
"arn:aws:ecs:us-west-2:1234567890:service-revision/myCluster/myService/01275892": 100,
"arn:aws:ecs:us-west-2:1234567890:service-revision/myCluster/myService/78652123": 0
},
"productionTrafficWeights": {}
}
Expectations at this stage:
Test traffic is in the process of moving towards the green service revision tasks.
This stage occurs after test traffic has been fully shifted to the new tasks.
The following shows an example payload for this lifecycle stage.
{
"serviceArn": "arn:aws:ecs:us-west-2:1234567890:service/myCluster/myService",
"targetServiceRevisionArn": "arn:aws:ecs:us-west-2:1234567890:service-revision/myCluster/myService/01275892",
"testTrafficWeights": {},
"productionTrafficWeights": {}
}
Expectations at this stage:
100% of test traffic moved towards the green service revision tasks.
This stage occurs when production traffic is being shifted to the green service revision tasks.
{
"serviceArn": "arn:aws:ecs:us-west-2:1234567890:service/myCluster/myService",
"targetServiceRevisionArn": "arn:aws:ecs:us-west-2:1234567890:service-revision/myCluster/myService/01275892",
"testTrafficWeights": {},
"productionTrafficWeights": {
"arn:aws:ecs:us-west-2:1234567890:service-revision/myCluster/myService/01275892": 100,
"arn:aws:ecs:us-west-2:1234567890:service-revision/myCluster/myService/78652123": 0
}
}
Expectations at this stage:
Production traffic is in the process of moving to the green service revision.
This stage occurs after production traffic has been fully shifted to the green service revision tasks.
{
"serviceArn": "arn:aws:ecs:us-west-2:1234567890:service/myCluster/myService",
"targetServiceRevisionArn": "arn:aws:ecs:us-west-2:1234567890:service-revision/myCluster/myService/01275892",
"testTrafficWeights": {},
"productionTrafficWeights": {}
}
Expectations at this stage:
100% of production traffic moved towards the green service revision tasks.
Lifecycle stages fall into two categories:
Single invocation stages - These stages are invoked only once during a service deployment:
PRE_SCALE_UP
POST_SCALE_UP
POST_TEST_TRAFFIC_SHIFT
POST_PRODUCTION_TRAFFIC_SHIFT
Recurring invocation stages - These stages might be invoked multiple times during a service deployment, for example when a rollback operation happens:
TEST_TRAFFIC_SHIFT
PRODUCTION_TRAFFIC_SHIFT
While lifecycle hooks are running, the deployment status will be IN_PROGRESS
for all lifecycle stages.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4