---
title: "CodeDeploy ScriptFailed: which hook, which script, which revision | Proofline"
description: "When a CodeDeploy lifecycle event fails with ScriptFailed, read that event's diagnostics on the instance target for the hook, the script and the log tail."
url: https://proofline.sh/learn/codedeploy-scriptfailed-lifecycle-event/
---

[Learning center](/learn/)

# CodeDeploy ScriptFailed: which hook, which script, which revision

When a CodeDeploy lifecycle event fails with ScriptFailed, read that event's diagnostics on the instance target for the hook, the script and the log tail. The hook name then tells you whether the failing script came from the new revision or from the last revision that succeeded, which decides what you fix.

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

## The signature and its nearby causes

An EC2/on-premises deployment fails, and the console or pipeline shows a deployment-level error such as `HEALTH_CONSTRAINTS`. That code counts instances: the deployment failed on too many instances for the deployment configuration's minimum healthy hosts. The cause sits one level down, on each failed instance's lifecycle events. Every lifecycle event carries a `diagnostics` object whose `errorCode` is one of six values. [ErrorInformation](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_ErrorInformation.html) · [Diagnostics](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_Diagnostics.html)

| `diagnostics.errorCode` | API description | Where to go |
| --- | --- | --- |
| `Success` | The specified script ran. | Not this event |
| `ScriptMissing` | The specified script was not found in the specified location. | The `location` in the AppSpec `hooks` section, relative to the bundle root |
| `ScriptNotExecutable` | The specified script is not a recognized executable file type. | File type and line endings in the bundle |
| `ScriptTimedOut` | The specified script did not finish running in the specified time period. | The hook's `timeout`; see [the agent and timeout guide](/learn/codedeploy-agent-timeout/) |
| `ScriptFailed` | The specified script failed to run as expected. | This guide |
| `UnknownError` | The specified script did not run for an unknown reason. | The `message` field and the agent log |

`ScriptFailed` has three nearby causes that look the same in the console. The script belongs to the old revision and runs before the new one is installed. The script belongs to the new revision and fails against the instance. Or the script is fine and the instance state it expects, such as a file or service left behind by an earlier deployment, is not there. The hook name separates the first two, and the log tail usually separates the third.

## Read the failed event's diagnostics

Use a read-only profile and replace the uppercase placeholders. Start with the deployment: its revision, the revision before it, and whether it was told to ignore stop failures. [DeploymentInfo](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_DeploymentInfo.html)

```
aws deploy get-deployment \
  --profile PROFILE --region REGION --deployment-id DEPLOYMENT_ID \
  --query 'deploymentInfo.{status:status,error:errorInformation,group:deploymentGroupName,config:deploymentConfigName,creator:creator,revision:revision,previous:previousRevision,ignoreStopFailures:ignoreApplicationStopFailures,overview:deploymentOverview}' \
  --output json --no-cli-pager
```

Then list the instance targets that failed and read one. `get-deployment-instance` still works for EC2/on-premises, but the API model marks it deprecated in favor of the target operations. [ListDeploymentTargets](https://docs.aws.amazon.com/cli/latest/reference/deploy/list-deployment-targets.html) · [get-deployment-target](https://docs.aws.amazon.com/cli/latest/reference/deploy/get-deployment-target.html) · [InstanceTarget](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_InstanceTarget.html)

```
aws deploy list-deployment-targets \
  --profile PROFILE --region REGION --deployment-id DEPLOYMENT_ID \
  --target-filters '{"TargetStatus":["Failed"]}' \
  --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.instanceTarget.{target:targetId,status:status,label:instanceLabel,events:lifecycleEvents[?status==`Failed`].{event:lifecycleEventName,start:startTime,end:endTime,code:diagnostics.errorCode,script:diagnostics.scriptName,message:diagnostics.message,log:diagnostics.logTail}}' \
  --output json --no-cli-pager
```

`scriptName` names the script, `message` carries CodeDeploy's summary, and `logTail` returns up to the last 4 KB of the diagnostic log. `instanceLabel` is `BLUE` or `GREEN` in a blue/green deployment. Read two or three failed targets before deciding: the same hook, script and tail on every instance points at the revision, while a failure on one instance only points at that instance's state. [LifecycleEvent](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_LifecycleEvent.html)

## The hook name says which revision ran the script

During a deployment, the CodeDeploy agent runs the `ApplicationStop`, `BeforeBlockTraffic` and `AfterBlockTraffic` scripts from the AppSpec file of the previous successful deployment. All other scripts come from the AppSpec file in the current deployment. The agent finds the previous revision through the `deployment-group-id_last_successful_install` file under `/opt/codedeploy-agent/deployment-root/deployment-instructions` on Linux. `ApplicationStop` does not run the first time you deploy to an instance, because no earlier AppSpec file exists there. [AppSpec hooks](https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html#appspec-hooks-server) · [Failed ApplicationStop, BeforeBlockTraffic or AfterBlockTraffic](https://docs.aws.amazon.com/codedeploy/latest/userguide/troubleshooting-deployments.html#troubleshooting-deployments-lifecycle-event-failures)

| Failed event | Script comes from | What a fix in the new revision does |
| --- | --- | --- |
| `ApplicationStop`, `BeforeBlockTraffic`, `AfterBlockTraffic` | The last successful revision on that instance | Nothing for this deployment, because the old script runs first |
| `BeforeInstall`, `AfterInstall`, `ApplicationStart`, `ValidateService`, `BeforeAllowTraffic`, `AfterAllowTraffic` | The revision being deployed | Fixes the next attempt |
| `DownloadBundle`, `Install`, `BlockTraffic`, `AllowTraffic` | Reserved for the agent; no scripts run | Read `message`, not a script |

AWS lists three reasons an old-revision hook fails: the location in the last-successful-install file no longer exists, the AppSpec file or scripts at that location are invalid, or the script has an error that can never succeed. For the last case, AWS documents one way through: create a new deployment that ignores those three events' failures. This is a change, not a read. It continues to `DownloadBundle` after a failed `ApplicationStop`, so the old script's work, such as stopping a process, may not have happened. [Ignore stop failures](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_DeploymentInfo.html) · [create-deployment](https://docs.aws.amazon.com/cli/latest/reference/deploy/create-deployment.html)

```
# Change: starts a new deployment that continues past ApplicationStop,
# BeforeBlockTraffic and AfterBlockTraffic failures.
aws deploy create-deployment \
  --profile PROFILE --region REGION \
  --application-name APPLICATION --deployment-group-name DEPLOYMENT_GROUP \
  --s3-location bucket=BUCKET,key=KEY,bundleType=zip \
  --ignore-application-stop-failures --no-cli-pager
```

Once that deployment succeeds, the new revision becomes the last successful one, and its own `ApplicationStop` script runs next time.

## Read the log tail for the cause

The tail holds the script's own output. A few patterns change the next step:

-   **The command or file does not exist.** AWS names `invalid character`, `command not found` and `file not found` as signs of non-printing characters, such as carriage returns, that some editors add to shell scripts. Check the script's line endings in the bundle. [Text editor problems](https://docs.aws.amazon.com/codedeploy/latest/userguide/troubleshooting-general.html#troubleshooting-text-editors)
-   **The script's own command failed.** A service that would not start, a migration that returned an error, or a permission denial is a defect in the revision or its configuration. Fix it in the revision.
-   **The tail is cut off.** 4 KB is often not enough. The full output of every script is in `scripts.log` under `/opt/codedeploy-agent/deployment-root/DEPLOYMENT_GROUP_ID/DEPLOYMENT_ID/logs/`, and `codedeploy-agent-deployments.log` under `deployment-root/deployment-logs/` collects it per deployment ID. [Files the agent installs](https://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent.html#codedeploy-agent-install-files)

## An illustrative example: two ScriptFailed deployments

These records are fictional. The application `orders` deploys revision `orders-58.zip` to the deployment group `orders-prod`, replacing `orders-57.zip`. Both deployments end with `HEALTH_CONSTRAINTS`.

In the first, every failed target shows the same event:

| Field | Value |
| --- | --- |
| `lifecycleEventName` | `ApplicationStop` |
| `diagnostics.errorCode` | `ScriptFailed` |
| `diagnostics.scriptName` | `scripts/stop_orders.sh` |
| `logTail` | The script's `systemctl stop` reports that the `orders` unit is not loaded |

`ApplicationStop` ran the stop script from `orders-57.zip`. Revision 58 renamed the systemd unit, but an operator had already applied the rename by hand on these hosts, so the old script stops a unit that is gone. Changing `orders-58.zip` would not reach this script. Redeploy revision 58 with `--ignore-application-stop-failures`, then check that no old `orders` process is still running before traffic returns.

In the second, the event is `AfterInstall`, the script is `scripts/migrate.sh` and the tail ends with the migration tool's error about a missing column. That script came from `orders-58.zip`, so the fix belongs in revision 58. A rollback redeploys revision 57, but CodeDeploy does not revert what earlier scripts did, so check the database state the migration left before you roll back. [Rollback behavior](https://docs.aws.amazon.com/codedeploy/latest/userguide/deployments-rollback-and-redeploy.html)

## Where the diagnostics mislead

-   The tail is the last 4 KB of output. An error printed early, followed by cleanup noise, is not in it.
-   `Diagnostics` describes scripts. When `DownloadBundle` fails, CodeDeploy reports `UnknownError` with messages such as `not opened for reading`, which AWS ties to S3 errors, instance profile permissions or a bucket in another Region. [DownloadBundle failures](https://docs.aws.amazon.com/codedeploy/latest/userguide/troubleshooting-deployments.html#troubleshooting-deployments-downloadbundle)
-   If every lifecycle event is `Skipped` or stays `Pending`, no script ran. The agent, its credentials or its network path are the cause; see [why CodeDeploy events stay pending](/learn/codedeploy-agent-timeout/).
-   The agent keeps archives of five revisions by default, and it rotates its own Linux log daily and deletes it after seven days. Copy the logs you need early. [Log cleanup](https://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent.html#codedeploy-agent-revisions-logs-cleanup)

A failure on one instance in a large group may not fail the deployment at all, depending on the minimum healthy hosts setting; [the health constraints guide](/learn/codedeploy-health-constraints/) works through the arithmetic. The [signature table](/learn/aws-deployment-failure-signatures/) lists the fields other AWS deployment services use for the same question.

## Questions

### Why does fixing my ApplicationStop script not fix the failed deployment?

`ApplicationStop` runs the script from the last revision that deployed successfully on that instance, not the one you are deploying. Deploy with `--ignore-application-stop-failures` once, and the fixed script becomes the one that runs next time.

### Where is the full output of a CodeDeploy hook script?

`get-deployment-target` returns only the last 4 KB in `diagnostics.logTail`. On a Linux instance, the full output is in `scripts.log` under the deployment's folder in `/opt/codedeploy-agent/deployment-root/`.

### What is the difference between ScriptFailed and ScriptTimedOut?

`ScriptFailed` means the script ran and failed to run as expected. `ScriptTimedOut` means it was still running when the hook's `timeout` expired. The default and maximum is 3,600 seconds per lifecycle event.

## 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

-   ### [CodeDeploy health constraints: failed instances or an impossible setting?](/learn/codedeploy-health-constraints/)
    
    Capacity overruns The Proofline team November 22, 2026 6 min read
    
-   ### [CodeDeploy events stuck in Pending: agent, endpoint or slow script](/learn/codedeploy-agent-timeout/)
    
    Deployment failures The Proofline team November 22, 2026 7 min read
