Automate deployment using AWS CodeDeploy

Reading Time: 6 minutes

In the CodeDeploy blog series, we are going to write two blogs the first blog covers the CodeDeploy theory-based. In the second blog, we will cover the full end-to-end automation practical of the application deployment using CodeDeploy and Jenkins. Let’s start aws CodeDeploy is basically a deployment service through which we can easily automate your deployment.

Why a deployment service?

We all know that this is the agility world, almost every company follows the agile methodology which means a large number of developers push the new functionality rapidly. We need to deliver those functionalities to the end-user.

codedeploy

There is need a deployment service through this we can automate the deployment of every new functionality to the different environment which handles all the deployment complexity internally and minimize the application downtime.

What is CodeDeploy?

AWS CodeDeploy is a fully managed deployment service using this we can automate software deployments to the following platforms:

  • Amazon EC2/ On-premises servers
  • AWS Lambda
  • Elastic Container Service (ECS)

AWS CodeDeploy makes it easier for you to rapidly release new features, helps you avoid downtime during application deployment, and handles the complexity of updating your applications.

The service scales according to your infrastructure, you can easily deploy to one instance or thousands.

Using the aws CodeDeploy, you can deploy an unlimited variety of application contents like :

  • code
  • serverless
  • AWS Lambda functions
  • web and configuration files
  • executables
  • packages
  • scripts
  • multimedia files

You do not need to make changes to your existing code before you can use CodeDeploy.

CodeDeploy supports various configuration management and continuous integration tools.

like Ansible, puppet, Jenkins bamboo, etc. you can easily integrate CodeDeploy to the above tools for end-to-end automation.

Benefits of AWS CodeDeploy

These are the following benefits which aws CodeDeploy provides:

  1. Server, serverless, and container applications: CodeDeploy supports EC2/On-premises servers, serverless aws lambda, and ECS container service you can deploy your application to any one of them which you want.
  2. Automated deployments: With the help of aws CodeDeploy service you can fully automate your application deployments.
  3. Minimize downtime: CodeDeploy provides a rolling update and blue/green deployment which helps to minimize the application downtime.
  4. Stop and rollback: Whenever deployment fails at any lifecycle hooks the CodeDeploy stop that application and rollback to the previous version.
  5. Centralized control: You can launch and track the status of your deployments through the CodeDeploy console or the AWS CLI
  6. Easy to adopt: CodeDeploy is platform-agnostic and works with any application. You can easily reuse your setup code. CodeDeploy can also integrate with your software release process or continuous delivery toolchain.
  7. Concurrent deployments: If you have more than one application that uses the EC2/On-Premises compute platform, CodeDeploy can deploy them concurrently to the same set of instances.

CodeDeploy Component

Application

The application in CodeDeploy is a collection of deployment groups and revisions. An EC2/On-Premises application uses the EC2/On-Premises compute platform.

Revision

A combination of an AppSpec file and application contents.

Deployment configuration

A Deployment setting. How the deployment takes place.

Deployment

Deploys a new revision that consists of application content and an AppSpec file.

Deployment group

Set of instances that you want to deploy your application. we can say its environment which can be DEV, QA or PROD.

AppSpec file

The AppSpec specifies how to deploy the application to the instances in a deployment group

CodeDeploy Deployment Types

CodeDeploy provides two deployment type which are :

In-place deployment:

In the In-Place deployment whenever new revision comes on S3 or Github then the running application (which is deployed on deployment group in which ) each instance is stopped the previous version and the latest application revision is installed.

There is three deployment configuration available for the In-Place deployment which are :

  1. OneAtATime: In this one instance is taken out from the running application and stopped the previous application then install a newer version of the application and the same procedure is applied for the remaining instances.
  2. HalfAtATime: In this half of the instances are taken out from the running application and stopped the previous application then install a newer version of the application and the same procedure is applied for the remaining half instances.
  3. AllAtOnce: In this, all instances are taken out from the running application and stopped the previous application then install a newer version of an application in one time.
codedeploy

Note: Only the EC2/On-Premises compute platform can use in-place deployments and not supported by aws Lambda or ECS.

Blue/Green Deployment

A blue/green deployment reroutes traffic from your application’s running environment ( blue ) where your previous version of the application is running to a new environment ( green ) where your new version of the application is running. Blue/green deployment supports all the CodeDeploy supported compute instances.

Your environment depends on your CodeDeploy application’s compute platform.

  • AWS Lambda: Traffic is shifted from one version of a Lambda function to a new version of the same Lambda function.
  • Amazon ECS: Traffic is shifted from a task set in your Amazon ECS service to an updated, replacement task set in the same Amazon ECS service.
  • EC2/On-Premises: Traffic is shifted from one set of instances in the original environment to a replacement set of instances.
Blue/green Deployment

Deployment configuration of Blue/Green deployment is based on the computing platform which are :

  • EC2/On-Premises: Which are same as we mention in the In-Place deployment configuration
  • Lambda: 
    Lambda supports three deployment configuration in blue/green deployment which are :
    1. Canary: Traffic is shifted in two increments according to your percentage of the traffic which you specified in the canary option.
    2. Linear: Traffic is shifted in equal increments with an equal number of minutes between each increment according to the specified percentage of traffic shifted in each increment and the number of minutes between each increment.
    3. All-at-once: All traffic is shifted from the original Lambda function to the updated Lambda function version all at once.
  • Elastic Container Service (ECS): We have only one deployment configuration which is AllAtOnce in which production traffic shifts from your Amazon ECS service’s original task set to a replacement task set all at once.

The workflow of In-Place Deployment:

IN-Place Deployment WorkFlow

In the above diagram which shows you how the IN-Place deployment works, let’s understand the above diagram :

First, Developer writes the code of the application which he/she wants to deploy to EC2 or On-Premises instances and pushes that application code to the Github. then he/she writes the application specification file ( AppSpec.yml file ) which is unique to CodeDeploy which defines the deployment actions you want to execute and push it into the root location of the project.

After that, you bundle your deployment content and the AppSpec file into an archive file. Then upload it to the Amazon S3 bucket or a GitHub repository.This archive file is called an application revision (or simply a revision).

Next, you provide the information about your deployment to the CodeDeploy. Such as which Amazon S3 bucket or GitHub repository to pull the revision from and the target instances which you want to deploy your application which is also called the deployment group.

Next, the CodeDeploy agent is running on each instance which is continuous polls CodeDeploy to determine what and when to pull from the specified Amazon S3 bucket or GitHub repository.

Finally, When the new deployment is created the CodeDeploy agent on each instance pulls the target revision from the Amazon S3 bucket or GitHub repository and, using the instructions in the AppSpec file, deploys the contents to the instance.

CodeDeploy keeps a record of your deployments so that you can get deployment status, deployment configuration parameters, instance health, and so on.

That’s all for this theory based CodeDeploy blog, Next Blog of this series based on practical.

Thank you for sticking to the end. If you like this blog, please do show your appreciation by giving thumbs-ups and share this blog and give me suggestions on how I can improve my future posts to suit your needs. Follow me to get updates on different technologies

knoldus Bottom Image

Written by 

Azmat Hasan is a Software Consultant at Knoldus Software LLP. He has done MCA from CDAC Noida in 2019. He has good knowledge of DevOps technologies i.e docker, Ansible, CI/CD(Jenkins, Bamboo), Kubernetes, Monitoring(Prometheus, Grafana), Logging(ELK Stack), etc. He is a self-motivated, enthusiastic person who believes in striving to achieve what we can sustain over a longer period of time, instead of working for short term benefits. He believe in working together to create synergy.