How to Deploy an App from GitHub with AWS CodeDeploy

Application development is comprised of different stages. One such critical step is app deployment and code management. In this article, we’re going to share how you can use a deployment system that will enable you to automate the deployment and updating of your application – AWS CodeDeploy. It’s one of the three AWS tools which will help you integrate, deploy, and manage your app on the cloud: CodeDeploy, CodeCommit, and CodePipeline.

What Exactly is AWS CodeDeploy?

AWS CodeDeploy is deployment system that enables a developer or a team of developers to automate the software release process. In other words, it is a collection of settings that relates to the environment on which the application is to be deployed, how many instances can be implemented at once, and so on. It efficiently deploys your code to a fleet of EC2 instances while leaving as much of the fleet online as possible. The size of a fleet can vary from a single instance to thousands of instances.
The first step to getting started with AWS Code deploys is setting up EC2 instances. Then, you’ll need to tag them – this will allow you to define deployment groups, install the CodeDeploy agent on your hosts, and set up trust-roles to allow communication between the CodeDeploy and CodeDeploy agents.

The Key Functions of CodeDeploy

CodeDeploy also specifies information regarding the trusted role which automates the communication between the various EC2 instances and CodeDeploy. However, CodeDeploy doesn’t specify the code to be deployed or what to do during the deployment. The code to be implemented is stored as an archive in S3 and is referred to as an Application Revision. The “how to deploy” component of CodeDeploy is specified by the AppSpec file located inside the Application Revision. Here’s what you need to know about them:

  • AppSpec: This file resides in the repo and communicates with the CodeDeploy by indicating applications to be deployed, the location in they are to be deployed to, and allow you to specify the lifecycle scripts. These scripts are to be run at different stages during deployment and can be used to stop the service, install dependencies, and run database migrations.
  • Application Revision: It is a zip file which contains all the codes to be deployed. You can create it by packaging up the entire repo or a sub-directory of the repo. This file must be stored in the application review using the syntax <application-root>/appspec.yml.

Since you will have one application in your repo when you package up the entire repo, you can then create your Application Revision (excluding the .git). When you do this, appsec.yml needs to be replaced in your repo root directory.
Now that we’ve learned what CodeDeploy is and established how it works, let’s move on to the steps which will show you how to deploy an application from GitHub with AWS CodeDeploy.

Deploying an Application from GitHub with AWS CodeDeploy

  1. Installing and setting up your GitHub account: First download and install GitHub on your system. If you want to use AWS CLI to install a revision from GitHub over the instance, also install and configure the AWS CLI.
  2. For creating a repository, you will be required to open GitHub account, so start with registering. You will just need to provide an email address, a username, and also the password.
  3. Creating a GitHub repository: The next step after registering is creating a repository which will be used to store a revision. If you have an existing repository, rename it to CodeDeployGitHubDemo and skip this step and move ahead. However if you don’t then follow these steps:

Now over the GitHub home page, perform either of the subsequent steps:

  1. Over Your repositories, select New Repository.
    Over navigation bar, select Create new (+), and pick New repository.
    Now, over Create a new repository page, perform the following task:
Over the Repository name box, type CodeDeployGitHubDemo.
Choose Public.
Remove Initialize this repository with README check box. You need to create a README.md file
in the following step.
Select Create repository
Now, after creating a repository, you will need to follow the following instruction
for using the command line. These guidelines differ from the operating system you're using:

For Unix or Linux: From the terminal, you need to run the below-mentioned commands, in sequence, where the username will be your GitHub username.

mkdir /tmp/CodeDeployGitHubDemo
cd /tmp/CodeDeployGitHubDemo
touch README.md
git init
git add README.md
git commit -m "My first commit"
git remote add origin https://github.com/user-name/CodeDeployGitHubDemo.git
git push -u origin master

You should then leave the command prompt open in the /tmp/CodeDeployGitHubDemo location.
For Windows: As an administrator, from the command prompt, run the following commands, in sequence:

mkdir c:\temp\CodeDeployGitHubDemocd c:\temp\CodeDeployGitHubDemonotepad README.md

Now, in the notepad save the README.md file. Close the notepad. Run the following commands, in sequence, where again the username will be your GitHub username:

git init
git add README.md
git commit -m "My first commit"
git remote add origin https://github.com/user-name/CodeDeployGitHubDemo.git
git push -u origin master

Then leave the command prompt open in the /tmp/CodeDeployGitHubDemo location.

  1. Uploading the Application to your GitHub Repository: When you’re uploading the application using a revision make sure it follows the guidelines in Plan a Revision and Add an AppSpec File which we discussed earlier.
  2. If the change follows the guidelines, then you’re ready for deploying the application to the instance.
  3. Procuring an Instance: You will need to create an Amazon EC2 instance running any server such as Linux, Windows, RHEL or Ubuntu instance configured for use in AWS CodeDeploy deployments. Once you have verified and installed an instance set with AWS CodeDeploy, proceed to the next step.
  4. Connecting the Application to the Instance: Now you are required to use the AWS CodeDeploy console for deploying the revision from the GitHub repository to the instance. Shadow the following steps for using the change:
  5. You need to sign into the AWS Management console and then open the AWS CodeDeploy console and sign in using the credentials used earlier.
    Select create new applications and key CodeDeployGitHubDemo-App.
    Now, over the deployment group name box, key in CodeDeployGitHubDemo-DepGrp and choose a type tag.
    Now, go to the Deployment Config, Service Role ARN.
    Select Create Application.

Over the Application details page, in Deployment groups, select the button next to CodeDeployGitHubDemo-DepGrp.
In the Actions menu, select Deploy New Revision.
Over the Create New Deployment page, in the Revision Type area, select My application is stored in GitHub.
Select Connect with GitHub. The page which appears will ask you to authorize AWS CodeDeploy for interacting with GitHub for the application known as CodeDeployGitHubDemo-App.
Shadow the instructions over the Sign in the page to sign in with the GitHub account.
Now, on the Authorize application page, select Authorize Application.
On the AWS CodeDeploy Create New Deployment page, in the Repository Name box, key in the GitHub username which you had used while signing in, followed by a forward slash (/), followed by the name of the repository where you pushed your application revision (for instance, My-GitHub-User-Name/CodeDeployGitHubDemo)
If you are not sure about value to type, or if you need to specify a different repository:

  1. In a different web browser tab, open your GitHub dashboard.
  2. In Your repositories, hover your mouse pointer on the target repository name. A tooltip will appear which will display the GitHub user or organization name, followed by a forward slash character (/), followed by the name of the repository. Key in this displayed value on to the Repository Name box.

Over the Commit ID box, key in the ID of the commit associated with the push of your application revision to GitHub.
If you are not sure of the value to type:

  1. In a different web browser tab, open your GitHub dashboard.
  2. In your repositories, select CodeDeployGitHubDemo.
  3. In the list of commits, search and copy the commit ID associated with the push of your application revision to GitHub. The ID is typically 40 characters in length and comprises both numbers and letters.
  4. Key in the commit ID into the Commit ID box.

Leave the Deployment Description box blank.
Leave the Deployment Config drop-down list at the default of CodeDeployDefault.OneAtATime,
and select Deploy Now.

Wrap-Up

You now know how to deploy an application with GitHub and AWS CodeDeploy. If you have any questions, be sure to leave a comment below. For more information about CodeDeploy and other development best practices on AWS, take a look at our Developer Fundamentals for AWS course. It’s jam-packed with information about CodeDeploy, CodeCommit, and CodePipeline.


Reference: Tutorial: Deploy an Application from GitHub Using AWS … (n.d.). Retrieved from http://docs.aws.amazon.com/codedeploy/latest/userguide/github-integ-tutorial.htm.

Written by

Sudhi is part of Cloud Technology Partners & is a trusted advisor and strategic consultant to many C level executives and IT Directors. He brings 18+ years diverse experience covering software, IT operations, cloud technologies, and management. Have led several global teams in HP, Sun/Oracle, SeeBeyond and few startups to deliver scalable and highly available business/technology products and solutions. He has expertise in systems management, monitoring and integrated SaaS and on-premise applications addressing a wide range of business problems.

Related Posts

— November 28, 2018

Two New EC2 Instance Types Announced at AWS re:Invent 2018 – Monday Night Live

Let’s look at what benefits these two new EC2 instance types offer and how these two new instances could be of benefit to you. Both of the new instance types are built on the AWS Nitro System. The AWS Nitro System improves the performance of processing in virtualized environments by...

Read more
  • AWS
  • EC2
  • re:Invent 2018
— November 21, 2018

Google Cloud Certification: Preparation and Prerequisites

Google Cloud Platform (GCP) has evolved from being a niche player to a serious competitor to Amazon Web Services and Microsoft Azure. In 2018, research firm Gartner placed Google in the Leaders quadrant in its Magic Quadrant for Cloud Infrastructure as a Service for the first time. In t...

Read more
  • AWS
  • Azure
  • Google Cloud
Khash Nakhostin
— November 13, 2018

Understanding AWS VPC Egress Filtering Methods

Security in AWS is governed by a shared responsibility model where both vendor and subscriber have various operational responsibilities. AWS assumes responsibility for the underlying infrastructure, hardware, virtualization layer, facilities, and staff while the subscriber organization ...

Read more
  • Aviatrix
  • AWS
  • VPC
— November 10, 2018

S3 FTP: Build a Reliable and Inexpensive FTP Server Using Amazon’s S3

Is it possible to create an S3 FTP file backup/transfer solution, minimizing associated file storage and capacity planning administration headache?FTP (File Transfer Protocol) is a fast and convenient way to transfer large files over the Internet. You might, at some point, have conf...

Read more
  • Amazon S3
  • AWS
— October 18, 2018

Microservices Architecture: Advantages and Drawbacks

Microservices are a way of breaking large software projects into loosely coupled modules, which communicate with each other through simple Application Programming Interfaces (APIs).Microservices have become increasingly popular over the past few years. The modular architectural style,...

Read more
  • AWS
  • Microservices
— October 2, 2018

What Are Best Practices for Tagging AWS Resources?

There are many use cases for tags, but what are the best practices for tagging AWS resources? In order for your organization to effectively manage resources (and your monthly AWS bill), you need to implement and adopt a thoughtful tagging strategy that makes sense for your business. The...

Read more
  • AWS
  • cost optimization
— September 26, 2018

How to Optimize Amazon S3 Performance

Amazon S3 is the most common storage options for many organizations, being object storage it is used for a wide variety of data types, from the smallest objects to huge datasets. All in all, Amazon S3 is a great service to store a wide scope of data types in a highly available and resil...

Read more
  • Amazon S3
  • AWS
— September 18, 2018

How to Optimize Cloud Costs with Spot Instances: New on Cloud Academy

One of the main promises of cloud computing is access to nearly endless capacity. However, it doesn’t come cheap. With the introduction of Spot Instances for Amazon Web Services’ Elastic Compute Cloud (AWS EC2) in 2009, spot instances have been a way for major cloud providers to sell sp...

Read more
  • AWS
  • Azure
  • Google Cloud
— August 23, 2018

What are the Benefits of Machine Learning in the Cloud?

A Comparison of Machine Learning Services on AWS, Azure, and Google CloudArtificial intelligence and machine learning are steadily making their way into enterprise applications in areas such as customer support, fraud detection, and business intelligence. There is every reason to beli...

Read more
  • AWS
  • Azure
  • Google Cloud
  • Machine Learning
— August 17, 2018

How to Use AWS CLI

The AWS Command Line Interface (CLI) is for managing your AWS services from a terminal session on your own client, allowing you to control and configure multiple AWS services.So you’ve been using AWS for awhile and finally feel comfortable clicking your way through all the services....

Read more
  • AWS
Albert Qian
— August 9, 2018

AWS Summit Chicago: New AWS Features Announced

Thousands of cloud practitioners descended on Chicago’s McCormick Place West last week to hear the latest updates around Amazon Web Services (AWS). While a typical hot and humid summer made its presence known outside, attendees inside basked in the comfort of air conditioning to hone th...

Read more
  • AWS
  • AWS Summits
— August 8, 2018

From Monolith to Serverless – The Evolving Cloudscape of Compute

Containers can help fragment monoliths into logical, easier to use workloads. The AWS Summit New York was held on July 17 and Cloud Academy sponsored my trip to the event. As someone who covers enterprise cloud technologies and services, the recent Amazon Web Services event was an insig...

Read more
  • AWS
  • AWS Summits
  • Containers
  • DevOps
  • serverless