Wednesday, August 3, 2016

Deploy Java application from GitHub to AWS

HOWTO from AWS tutorial

AWS tutorial video  Code Deploy Setup (IAM, EC2)

GitHub for AWS tutorial video

AWS CodeDeploy tutorial video

Steps to create running AWS EC2 instance

Create AWS free account

Getting started :

Create AWS account

Create own Linux instance

Connect to AWS Linux instance via ssh

[dave@localhost aws]$ chmod 400 dave_amazon.pem
[dave@localhost aws]$ ssh -i "dave_amazon.pem"

       __|  __|_  )
       _|  (     /   Amazon Linux AMI
8 package(s) needed for security, out of 17 available
Run "sudo yum update" to apply all updates.

Install AWS tools on Fedora

[root@localhost ~]# dnf install  awscli
Dependencies resolved.
 Package                  Arch         Version                               Repository     Size
 awscli                   noarch       1.10.45-1.fc23                        updates       868 k
 python3-botocore         noarch       1.4.35-1.fc23                         updates       1.8 M
 python3-colorama         noarch       0.3.2-2.fc23                          fedora         29 k
 python3-docutils         noarch       0.12-0.3.20140510svn7747.fc23         fedora        1.5 M
 python3-jmespath         noarch       0.9.0-1.fc23                          updates        43 k
 python3-pyasn1           noarch       0.1.8-1.fc23                          fedora        108 k
 python3-rsa              noarch       3.4.1-1.fc23                          updates        72 k
 python3-s3transfer       noarch       0.0.1-2.fc23                          updates        29 k

Transaction Summary
Install  8 Packages

Total download size: 4.5 M
Installed size: 27 M
Is this ok [y/N]: 
Paste your text here.


[dave@localhost aws]$ aws --version
aws-cli/1.10.45 Python/3.4.3 Linux/4.5.7-200.fc23.x86_64 botocore/1.4.35

 Add AWS IAM access keys

[dave@localhost aws]$ aws configure

Check running instances 

[dave@localhost aws]$ aws ec2 describe-instances 
    "Reservations": [
            "Instances": [

Integrating AWS CodeDeploy with GitHub

Setup roles in IAM

Amazon AWS Java samples

Create GitHub repository with sample application

User guide GitHub - AWS integration 

Create application - see tutorial page
  Step 5: Deploy the Application to the Instance

Connect with GitHub

Deploy AWS sample Linux

Check AWS CodeDeploy console

Deploy fails with HEALTH_CONSTRAINTS

It is necessary to install CodeDeploy on instance
Follow this tutorial :

Install or reinstall the AWS CodeDeploy agent for Amazon Linux or RHEL

[ec2-user@ip-172-31-21-129 ~]$ wget
--2016-08-07 13:45:20--
Resolving (
Connecting to (||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 13359 (13K) []
Saving to: ‘install’

install                    100%[======================================>]  13.05K  78.6KB/s    in 0.2s    

2016-08-07 13:45:21 (78.6 KB/s) - ‘install’ saved [13359/13359]

Check installation success
[ec2-user@ip-172-31-21-129 ~]$ sudo service codedeploy-agent status
The AWS CodeDeploy agent is running as PID 2660

Deploy application from GithHub  using CodeDeploy - Deployments

Access application using public IP address

Check log on EC2 instance

c2-user]# tail -500f /var/log/httpd/access_log - - [24/Sep/2016:18:03:53 +0000] "GET / HTTP/1.1" 200 911 "-" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:48.0) Gecko/20100101 Firefox/48.0"

Sample app Linux

Sample Tomcat application on GitHub

You can also download sample app from Amazon S3
[dave@localhost aws]$ aws s3 cp s3://aws-codedeploy-eu-central-1/samples/latest/ . --region eu-central-1
download: s3://aws-codedeploy-eu-central-1/samples/latest/ to ./

[dave@localhost aws]$ unzip -l 
  Length      Date    Time    Name
---------  ---------- -----   ----
       34  11-03-2014 22:42   scripts/install_dependencies
       33  11-03-2014 22:43   scripts/start_server
      105  11-03-2014 22:43   scripts/stop_server
      359  11-03-2014 22:42   appspec.yml
      717  11-03-2014 22:42   index.html
    10884  11-03-2014 22:42   LICENSE.txt
---------                     -------
    12132                     6 files