• hey@aysharshad.com
  • Norway
AWS
An Efficient way to Deploy your Code to Amazon EC2

An Efficient way to Deploy your Code to Amazon EC2

The ways of the monolith deployments require Application teams to deploy their code on AWS Elastic Compute Cloud almost every day. With an increasing focus on automation luckily now we have tools to automate this boring procedure as well.

Hence in this article, I will be discussing a less effective old way of deploying code on AWS EC2 instances and a new more effective way of doing the same.

Old Inefficient Way of Code Deployment on AWS EC2

About 4 to 5 years ago if you wanted to deploy you would possibly deploy on a Dev or Testing (Quality Testing or User Acceptance Testing) environment first. And once successful you would deploy on the Production Environment. Not only was this process manual but also unreliable. 

Why was it Unreliable?

For the following resons:

  1. Every Machine is Different: Even if you tested your code in a test environment. Still, there is a chance that it will destroy your environment and things won’t work out as expected.
  2. Manual Deployment means Manual Rollback: If your code impacts the environment then it means if you have to roll back your latest change then it requires manual rollback procedures as well.

Hence in order to fix these problems, we need to introduce two new strategies in our Code Deployment Procedures if you have a monolith system.

New Approach of Code Deployment

The new approach simply introduces two new units in your current strategy.

Have a Blue-Green Deployment
  1. This means you’ll have two identical environments. One will be called Blue Environment which will be turned off after deployment is successful. Green is the actual production environment.
  2. Both environments should be reachable via a load balancer and both should be actively serving the traffic. These environments can be part of an Auto Scaling Group as well because in the case of faulty instances you might have to spin new servers to take the load as well.
  3. Deploy your code on the Blue environment first. If the traffic is still served by both environments then it means deployment was successful. Now you can deploy in the Green environment as well. And turn off the Blue Environment.
  4. In case the deployment was not successful in the Blue environment simply take it down while the Auto Scaling Group spins another one to take the load.
Use AWS Code Deploy for Deploying Code

Now in order to fix the manual deployment part, you can use AWS Code Deploy. Which only requires you to simply install its agent in the AWS EC2 instances. And you can manage your deployments remotely without having to log in on a server.

  1. Choose the server on which you need the latest version of code.
  2. Deploy the Code.
  3. And Voila! you’re done. You can follow the same procedure for both Blue and Green Deployments.
  4. In case of a failure, you can roll back the deployment very easily as well.
error: Content is protected. You are automatically reported to the Authorities!