Is there a way to speed up AWS CodeDeploy

I'm using AWS CodeDeploy to deploy my sites, and I noticed it's not very consistent in speed; sometimes it's pretty fast, but other times each step of a deployment can take minutes. This is pretty annoying when a deployment should be performed fast, in case of bugs or outages.

I can't find any documentation on the speed of CodeDeploy though, and also I can't seem to find any logic in when it's slow or when it's fast. Is there any way to speed it up and is there any way to know what's taking so long?


Solution 1:

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 2:

BlockTraffic and AllowTraffic

Simply adjusting your target group's health check settings can shave off a couple minutes.

Before

enter image description here enter image description here

After

enter image description here enter image description here

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