AWS Certified Developer – Associate (DVA-C02)Troubleshooting and MonitoringEasy

A developer is using AWS CodeDeploy to deploy an application to a fleet of Amazon EC2 instances. Deployments often fail with a 'Script timed out' error during the `ApplicationStop` lifecycle event. The application takes a few minutes to gracefully shut down. The CodeDeploy agent logs on the EC2 instances show the `ApplicationStop` script starting but then abruptly terminating without completing. What is the MOST efficient way to resolve this issue?

  1. AModify the `ApplicationStop` script to force-kill the application process immediately.
  2. BIncrease the `timeout` setting for the `ApplicationStop` hook in the `appspec.yml` file.
  3. CIncrease the EC2 instance size to provide more resources for the shutdown process.
  4. DConfigure a CloudWatch alarm to detect long-running `ApplicationStop` events and notify the developer.
Show answer & explanation

Correct answer: B. Increase the `timeout` setting for the `ApplicationStop` hook in the `appspec.yml` file.

The 'Script timed out' error directly indicates that the CodeDeploy agent terminated the script because it exceeded its allotted time. Since the application takes a 'few minutes' to gracefully shut down, increasing the `timeout` setting for the `ApplicationStop` hook in the `appspec.yml` file is the most direct and efficient solution to allow the script enough time to complete.

Why the other options are wrong

  • A. Forcing the application to kill immediately might prevent the timeout but bypasses graceful shutdown, potentially leading to data loss or corruption. This is not a desirable solution.
  • C. Increasing EC2 instance size is unlikely to resolve a script timeout unless the shutdown process is CPU/memory bound, which is rare. The issue is about the allowed execution time, not resource availability.
  • D. A CloudWatch alarm would only notify about the problem, not resolve it. The problem is already known ('Script timed out' errors).

CodeDeploy AppSpec Hook Timeout

In AWS CodeDeploy, each lifecycle event hook (e.g., `ApplicationStop`, `BeforeInstall`) defined in the `appspec.yml` file has an associated `timeout` setting. If a script executed during a hook exceeds this timeout, CodeDeploy terminates the script and marks the deployment as failed with a 'Script timed out' error.

  • Configurable per hook in `appspec.yml`.
  • Default timeout is 300 seconds (5 minutes) for most hooks.
  • Essential to match the timeout with the expected execution time of the script.

Memory trick: CodeDeploy Timeout: The `appspec.yml` hook's patience is thin, just extend its `timeout` to win.

More Troubleshooting and Monitoring questions