Is there a way to speed up AWS CodeDeploy
Solution 1:
BlockTraffic and AllowTraffic
Simply adjusting your target group's health check settings can shave off a couple minutes.
Before
After
Explanation
This works because BlockTraffic
and AllowTraffic
both wait for successful health checks. The default health check interval is 1 check every 30 seconds, and a successful health check needs 5 consecutive 200 responses. Thus it takes more than 2 min 30 seconds by default. And that's for every EC2 instance. Decreasing the health check interval and limiting the number of successful checks needed will improve deployment time.
Solution 2:
CodeDeploy does very little by default - it grabs the code from S3 or Github, then runs your scripts per the appspec.yml
file's instructions.
If your deployments are grabbing gigabytes of data from S3, you'll find that takes some time for the data transfer (particularly on smaller EC2 instances with limited bandwidth), but other than that deployment delays are much more likely to be due to whatever you're doing in your deployment scripts.
The steps in a CodeDeploy deployment are:
- ApplicationStop - you control this hook
- DownloadBundle - CodeDeploy grabs code from S3/Github
- BeforeInstall - you control this hook
- Install - CodeDeploy copies code from a temp location to the final destination
- AfterInstall - you control this hook
- ApplicationStart - you control this hook
- ValidateService - you control this hook
The bolded ones are up to CodeDeploy, the others are up to you. If you're seeing varying delays in the bolded ones, contact AWS support, but otherwise chances are you need to investigate your hooks.
Solution 3:
Another setting to check is the Target Group's "Deregistration delay". My health check settings were already low and this was the bottleneck in my case.