Continuous Deployment with AWS CodeDeploy & Github by@mlabouardy

Continuous Deployment with AWS CodeDeploy & Github

October 21st 2017 15,691 reads
Read on Terminal Reader
react to story with heart
react to story with light
react to story with boat
react to story with money
image
Mohamed Labouardy HackerNoon profile picture

Mohamed Labouardy

image

This post will walk you through how to AutoDeploy your application from Github using AWS CodeDeploy.

Let’s start first by creating 2 IAM roles we will use in this tutorial:

  • IAM role for CodeDeploy to talk to EC2 instances.
  • IAM role for EC2 to access S3.

1 — CodeDeployRole

Go to AWS IAM Console then navigate to “Roles“, choose “Create New Role“, Select “CodeDeploy” and attach “AWSCodeDeployRole” policy:

image

2 — EC2S3Role

Create another IAM role, but this time choose EC2 as the trusted entity. Then, attach “AmazonS3ReadOnlyAccess” policy:

image

Now that we’ve created an IAM roles, let’s launch an EC2 instance which will be used by CodeDeploy to deploy our application.

3 — EC2 Instance

Launch a new EC2 instance with the IAM role we created in last section:

image

Next to User Data type the following script to install the AWS CodeDeploy Agent at boot time:

image

Note: make sure to allow HTTP traffic in the security group.

image

Once created, connect to the instance using the Public IP via SSH, and verify whether the CodeDeploy agent is running:

image

4 — Application

Add the appspec.yml file to the application to describe to AWS CodeDeploy how to manage the lifecycle of your application:

The BeforeInstall, will install apache server:

The AfterInstall will restart apache server

5 — Setup CodeDeploy

Go to AWS CodeDeploy and create a new application:

image

Select In-Place deployement (with downtime):

image

Click on “Skip“, because we already setup our EC2 instance:

image

The above will take you to the following page where you need to give a name to your application:

image

Select the EC2 instance and assign a name to the deployment group:

image

Select the CodeDeployRole we created in the first part of the tutorial:

image

Then click on “Deploy“:

image

Create a deployment, select Github as the data source:

image

Just select “Connect to GitHub“. Doing that will pop up a new browser window, take you to Github login where you will have to enter your username and password

image

After that come back to this page, and you should see something like below, just enter the remaining details and click “Deploy

image

This will take you to a page as follows:

image

If you point your browser to the EC2 public IP, you should see:

image

Now, let’s automate the deployment using Github Integrations.

6 — Continuous Deployment

Go to IAM Dashboard, and create a new policy which give access to register and create a new deployment from Github.

image

Next, create a new user and attach the policy we created before:

image

Note: copy to clipboard the user AWS ACCESS ID & AWS SECRET KEY. Will come handy later.

7 — Github Integration

Generate a new token to invoke CodeDeploy from Github:

image

Once the token is generated, copy the token and keep it. Then, add AWS CodeDeploy integration:

image

Fill the fields as below:

image

Finally, add Github Auto Deployment

image

Fill the form as below:

image

To test it out, let’s edit a file or commit a new file. You should see a new deployment on AWS CodeDeploy:

image

react to story with heart
react to story with light
react to story with boat
react to story with money

Related Stories

L O A D I N G
. . . comments & more!