---
title: "CodeDeploy ECS blue/green rollback: failed hook or unhealthy task set | Proofline"
description: "Read the ECS target's lifecycle events: a failed hook event points at its validation Lambda, a stalled Install at the replacement task set."
url: https://proofline.sh/learn/codedeploy-ecs-blue-green-hook-failed/
---

[Learning center](/learn/)

# CodeDeploy ECS blue/green rollback: failed hook or unhealthy task set

Read the ECS target's lifecycle events: a failed hook event points at its validation Lambda, a stalled Install at the replacement task set. The hook event's duration then separates a function that reported Failed from one that never reported at all.

Deployment failures The Proofline team November 22, 2026 6 min read

## The signature and its nearby causes

An ECS service uses the `CODE_DEPLOY` deployment controller. A CodeDeploy blue/green deployment creates a replacement task set, routes test traffic to it if a test listener exists, then shifts production traffic. The deployment ends `Failed`, and if automatic rollback is configured, traffic returns to the original task set. CodeDeploy rolls back an ECS deployment by rerouting traffic from the replacement task set to the original one. [Deployments on the ECS platform](https://docs.aws.amazon.com/codedeploy/latest/userguide/deployment-steps-ecs.html) · [Blue/green with CodeDeploy](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/deployment-type-bluegreen.html)

Three causes leave that same outcome:

-   **The hook function reported `Failed`.** A Lambda function named in the AppSpec `Hooks` section ran its checks and called `PutLifecycleEventHookExecutionStatus` with `Failed`.
-   **The hook function never reported.** CodeDeploy considers the deployment failed if the validation function does not notify it within one hour. A function that crashes, times out, lacks permission to call CodeDeploy or sends the wrong IDs ends the same way.
-   **The replacement task set never became healthy.** No hook failed; the new tasks did not start or did not pass health checks, and CodeDeploy timed out waiting for them.

[AppSpec hooks for ECS](https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html#appspec-hooks-ecs) · [PutLifecycleEventHookExecutionStatus](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_PutLifecycleEventHookExecutionStatus.html)

## Read the ECS target's lifecycle events

Use a read-only profile and replace the uppercase placeholders. Read the deployment first, then its single ECS target. [DeploymentInfo](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_DeploymentInfo.html) · [ECSTarget](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_ECSTarget.html)

```
aws deploy get-deployment \
  --profile PROFILE --region REGION --deployment-id DEPLOYMENT_ID \
  --query 'deploymentInfo.{status:status,error:errorInformation,messages:deploymentStatusMessages,rollback:rollbackInfo,autoRollback:autoRollbackConfiguration,config:deploymentConfigName,created:createTime,completed:completeTime}' \
  --output json --no-cli-pager

aws deploy list-deployment-targets \
  --profile PROFILE --region REGION --deployment-id DEPLOYMENT_ID \
  --query 'targetIds' --output json --no-cli-pager

aws deploy get-deployment-target \
  --profile PROFILE --region REGION --deployment-id DEPLOYMENT_ID --target-id TARGET_ID \
  --query 'deploymentTarget.ecsTarget.{status:status,events:lifecycleEvents[].{event:lifecycleEventName,status:status,start:startTime,end:endTime,code:diagnostics.errorCode,message:diagnostics.message},taskSets:taskSetsInfo[].{id:identifer,label:taskSetLabel,status:status,desired:desiredCount,running:runningCount,pending:pendingCount,weight:trafficWeight,targetGroup:targetGroup.name}}' \
  --output json --no-cli-pager
```

The field really is spelled `identifer` in the API. The events run in this order: `BeforeInstall`, `Install`, `AfterInstall`, `AllowTestTraffic`, `AfterAllowTestTraffic`, `BeforeAllowTraffic`, `AllowTraffic`, `AfterAllowTraffic`. Only the hook events run your functions; `Install`, `AllowTestTraffic` and `AllowTraffic` are CodeDeploy's own steps. `taskSetLabel` marks the original task set `BLUE` and the replacement `GREEN`. [ECSTaskSet](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_ECSTaskSet.html)

| First event not `Succeeded` | Its duration | Most likely cause | Next read |
| --- | --- | --- | --- |
| A hook such as `AfterAllowTestTraffic` | Minutes, close to your test's run time | The function reported `Failed` | The function's log for the failing check |
| A hook | About one hour | CodeDeploy never received a status | The function's log, errors and execution role |
| `Install` | Long, with the `GREEN` task set below its desired count | The replacement tasks did not become healthy | ECS service events and the green target group |

The `errorInformation.code` enum includes `HOOK_EXECUTION_FAILURE`, `ECS_UPDATE_ERROR` and `TIMEOUT`, but the API reference does not describe the first two. Read the code together with the message and the lifecycle events, not on its own. [ErrorInformation](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_ErrorInformation.html)

## When a hook failed: read the function

CodeDeploy invokes the hook function with a `DeploymentId` and a `LifecycleEventHookExecutionId` in the event. The function must pass both back in `PutLifecycleEventHookExecutionStatus` with a status of `Succeeded` or `Failed`. Lambda writes to the log group `/aws/lambda/FUNCTION_NAME` by default, so search it for the deployment ID. [Sample hook function](https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html#reference-appspec-file-structure-hooks-section-structure-ecs-sample-function) · [LoggingConfig](https://docs.aws.amazon.com/lambda/latest/api/API_LoggingConfig.html)

```
fields @timestamp, @logStream, @message
| filter @message like /DEPLOYMENT_ID/ or @message like /ERROR|Error|Task timed out/
| sort @timestamp asc
| limit 100
```

Run it over the hook event's `start` to `end` window. Each of three results sends you somewhere different:

-   **A test result and a call reporting `Failed`.** The function worked and the check it runs failed. The replacement task set answered on the test listener, but not the way the test expects. Fix the release, or the test if the test is wrong.
-   **An error before any call to CodeDeploy.** The function crashed or timed out, so CodeDeploy waited out the hour. Fix the function.
-   **An access denial on the status call.** AWS lists a missing `codedeploy:PutLifecycleEventHookExecutionStatus` permission on the function's execution role as a cause of a deployment that times out waiting for the hook. [Troubleshoot ECS deployments](https://docs.aws.amazon.com/codedeploy/latest/userguide/troubleshooting-ecs.html)

No log at all for that window means the function was not invoked. Check that the AppSpec names the right function and that the CodeDeploy service role can invoke it.

## When the task set failed: read ECS

If `Install` never completed, no hook is at fault. For a deployment that times out waiting for the replacement task set, AWS's first step is the ECS service events: find out why the replacement tasks are not becoming healthy. The task set's `externalId` holds the CodeDeploy deployment ID, and `stabilityStatus` stays `STABILIZING` until the running count matches the desired count and every task reports healthy to its load balancer, service discovery and container health checks. [Troubleshoot ECS deployments](https://docs.aws.amazon.com/codedeploy/latest/userguide/troubleshooting-ecs.html) · [TaskSet](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_TaskSet.html)

```
aws ecs describe-services \
  --profile PROFILE --region REGION --cluster CLUSTER --services SERVICE \
  --query 'services[0].{controller:deploymentController.type,taskSets:taskSets[].{id:id,deployment:externalId,status:status,definition:taskDefinition,desired:computedDesiredCount,running:runningCount,pending:pendingCount,stability:stabilityStatus,targetGroups:loadBalancers[].targetGroupArn},events:events[:15].[createdAt,message]}' \
  --output json --no-cli-pager

aws elbv2 describe-target-health \
  --profile PROFILE --region REGION --target-group-arn GREEN_TARGET_GROUP_ARN \
  --query 'TargetHealthDescriptions[].{target:Target.Id,port:Target.Port,state:TargetHealth.State,reason:TargetHealth.Reason}' \
  --output table --no-cli-pager
```

From here the failure is an ordinary ECS startup or health check failure on the new task definition, and the stopped tasks' stop codes sort it; see the [signature table](/learn/aws-deployment-failure-signatures/). Service auto scaling during the deployment is a separate cause AWS documents: if a scaling event occurs during a blue/green deployment and the service does not reach steady state within 5 minutes, CodeDeploy stops the deployment and marks it failed. [Blue/green considerations](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/deployment-type-bluegreen.html)

## An illustrative example: one service, two rollbacks

These records are fictional. The service `checkout` moves from `checkout:41` to `checkout:42` through CodeDeploy with a test listener on port 8443 and an `AfterAllowTestTraffic` hook function, `checkout-smoke-test`.

| Event | First rollback | Second rollback |
| --- | --- | --- |
| `Install` | `Succeeded`, 3 minutes | `Failed` after a long wait |
| `AllowTestTraffic` | `Succeeded` | Not reached |
| `AfterAllowTestTraffic` | `Failed`, 2 minutes | Not reached |
| `GREEN` task set | 4 running of 4 | 0 running of 4 |

In the first rollback the replacement tasks were healthy and served test traffic. The hook ran for two minutes, and its log shows the smoke test's checkout request returning a 500 from `checkout:42`, followed by a status call with `Failed`. The release is the cause.

In the second, no hook ran. The ECS service events show replacement tasks starting and stopping, and the stopped tasks carry `TaskFailedToStart` with a reason that names a missing log group in `checkout:42`. The fix is in the task definition, and the smoke test had nothing to do with it.

A third pattern would be `AfterAllowTestTraffic` failing after almost exactly one hour with no `Failed` status in the function's log. That points at the function or its permissions, not at `checkout:42`.

## Where this reading stops

-   A hook proves only what its test checks. A passing `AfterAllowTestTraffic` hook says the replacement task set answered the test's requests on the test listener, not that it handles production traffic.
-   A CloudWatch alarm attached to the deployment group can also stop the deployment and trigger a rollback. The Lambda alias guide separates [an alarm from a hook](/learn/lambda-alias-canary-rollback/), and the same reads apply here.
-   When validation fails and rollbacks are configured, CodeDeploy returns the components to their state when the deployment started, so the replacement task set does not stay for inspection. Read its stopped tasks and the service events promptly. [AfterAllowTestTraffic outcomes](https://docs.aws.amazon.com/codedeploy/latest/userguide/deployment-steps-ecs.html#deployment-steps-what-happens)
-   This guide covers the `CODE_DEPLOY` deployment controller. The ECS developer guide also documents a native ECS blue/green deployment type, which uses its own configuration model and hook format.

## Questions

### Why did my CodeDeploy ECS deployment fail after exactly one hour?

CodeDeploy treats a hook as failed if the validation function does not report a status within one hour. Check the function's log for a crash or timeout before the status call, and check that its execution role allows `codedeploy:PutLifecycleEventHookExecutionStatus`.

### How do I tell a failed hook from unhealthy replacement tasks?

Read the ECS target's lifecycle events with `get-deployment-target`. A failed hook event such as `AfterAllowTestTraffic` points at the hook function, while a failed or stalled `Install` with the `GREEN` task set below its desired count points at the replacement tasks.

### What does the AfterAllowTestTraffic hook run against?

It runs after the test listener serves traffic to the replacement task set, so a test there reaches the new tasks before production traffic moves. Its result can trigger a rollback.

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Lambda canary rolled back by CodeDeploy: alarm or traffic hook](/learn/lambda-alias-canary-rollback/)
    
    Deployment failures The Proofline team November 22, 2026 7 min read
    
-   ### [AWS deployment failure signatures: startup, placement, health, routing or scaling](/learn/aws-deployment-failure-signatures/)
    
    Deployment failures The Proofline team November 22, 2026 9 min read
