Deploy Code to EC2 using Code Deploy and GitHub Actions

Vinayak Pandey
AVM Consulting Blog
3 min readJun 11, 2021

--

In this post we’ll see how we can use Code Deploy And GitHub Actions to deploy our code to EC2 instances.

Reference: We’ll refer to following article and use Terraform to build the infra. So I won’t do much explaining about what we are going to do. You can go through the article once to understand the workflow.

Step 1: Fork

Fork the following: https://github.com/vinycoolguy2015/FlaskAppCodeDeploy.git (which I forked from https://github.com/azzan-amin-97/FlaskAppCodeDeploy.git and made some changes in appspec file).

Step 2: Get Terraform code

Get Terraform code from https://github.com/vinycoolguy2015/awslambda/tree/master/github_actions_ec2 and change git repo url in script.tpl file(line 14). Also create an SSH key using ssh-keygen command.

Now apply the code.

This will create our code deploy job along with an auto-scaling group with 2 EC2 instances, running behind an ALB. Once setup is created, try accessing ALB…

--

--