Question

Difficulty: HardAWS CodeDeploy

A developer is performing an in-place deployment of a new application revision to a fleet of Amazon EC2 instances using AWS CodeDeploy. The developer updated a cleanup script named 'stop-server.sh' in the new revision and referenced it in the 'ApplicationStop' lifecycle hook of the 'appspec.yml' file. However, the deployment fails during the 'ApplicationStop' phase. Investigation reveals that the 'stop-server.sh' script currently residing on the instances (from the previous deployment) has a syntax error that causes it to exit with a non-zero status, whereas the updated script in the new deployment bundle has this error fixed. Which of the following explains why the deployment failed and how the developer can successfully deploy the new application revision?

  1. A
    CodeDeploy executes the 'ApplicationStop' hook using the script from the new deployment bundle. The deployment failed because the new bundle was not yet downloaded, which the developer must resolve by changing the hook in the appspec.yml file to 'BeforeInstall'.
  2. B
    CodeDeploy failed to run the script because the EC2 instance profile lacks the required trust policy to assume the CodeDeploy service role. The developer must update the IAM role trust policy to allow the EC2 service principal to assume the CodeDeploy role.
  3. CodeDeploy executes the 'ApplicationStop' hook using the script from the previously deployed revision on the instances. The developer can bypass this failure by redeploying the new revision with the ignore application stop failures option enabled.Answer
  4. D
    CodeDeploy failed to execute the script because the credentials required by 'stop-server.sh' were stored in Systems Manager Parameter Store rather than Secrets Manager. The developer must migrate the parameters to AWS Secrets Manager to allow script execution.

Answer

CodeDeploy executes the ApplicationStop hook using the script from the previously deployed revision on the instances. The developer can bypass this failure by redeploying the new revision with the ignore application stop failures option enabled.
The correct option is correct because during an in-place deployment, CodeDeploy runs the ApplicationStop lifecycle hook using the scripts and appspec.yml from the previous successful deployment revision. Since the script on the instances has a bug, the hook fails and prevents the deployment from proceeding. Enabling the ignore application stop failures option allows CodeDeploy to bypass this hook's failure and successfully deploy the new version.

Step-by-Step Solution

1
Analyze the execution context of lifecycle hooks in an in-place CodeDeploy deployment.
Identify that the ApplicationStop hook occurs before the new revision bundle is downloaded and runs using the appspec.yml and scripts from the previously successful deployment revision.
This explains why the syntax error in the old version of the script causes the new deployment to fail, even though the script is fixed in the new revision bundle.
2
Evaluate recovery mechanisms for failing ApplicationStop scripts in CodeDeploy.
Determine that CodeDeploy allows bypassing ApplicationStop script failures using the '--ignore-application-stop-failures' flag in the AWS CLI or by checking the equivalent option in the AWS Management Console.
Since the local script on the EC2 instances is broken and cannot exit successfully, bypassing the hook is the only automated way to allow the new, fixed bundle to be downloaded and installed.

Key Concept

AWS CodeDeploy EC2 in-place deployment lifecycle hook execution and failure handling
Estimated Time:2m 0s
Rate this question