AWS CodeDeploy fails at Application Stop
April 23, 2020
April 23, 2020
There are times when you have a CodeDeploy process that may fail to show that the most recent event is ApplicationStop.
According to the AWS documentation here,
During a deployment, the CodeDeploy agent runs the scripts specified for ApplicationStop, BeforeBlockTraffic, and AfterBlockTraffic in the AppSpec file from the previous successful deployment. (All other scripts are run from the AppSpec file in the current deployment.) If one of these scripts contains an error and does not run successfully, the deployment can fail.
In my particular case, the appspec.yml file I was using didn’t have anything defined in the ApplicationStop, BeforeBlockTraffic or AferBlockTraffic hooks. However, the solution suggested does work.
If the cause of the failure is a script from the last successful deployment that never runs successfully, create a deployment and specify that the ApplicationStop, BeforeBlockTraffic, and AfterBlockTraffic failures should be ignored.
- From the failed deployment in the console, select the ‘Copy deployment’ button
- On the Create deployment page scroll down a bit and find the Additional deployment behavior settings box and select the checkbox next to Don’t fail the deployment to an instance if this lifecycle even on the instance fails. This is going to allow the deployment to continue on the next run.
- Select the Revision file type from the drop-down in the Deployment settings box
- Click on the Create deployment button at the bottom of the page.
- Your deployment should then be successful.
If you are triggering your deployment from a pipeline, like I was, you might want to trigger the pipeline again just to be sure that you ‘cleared’ this out. I have seen cases where this has popped up a few times. In my case, I had a CloudWatch alarm that gets triggered by the failure event that triggers a Lambda function to perform the actions above. This way, on the rare occasion that it does happen, it just corrects itself but lets me know and I can take a look if there is time.
Advanced Data Engineering Platform for Cleansing, Preprocessing and Analytics