Wednesday, August 3, 2016

Deploy Java application from GitHub to AWS

HOWTO from AWS tutorial


AWS tutorial video  Code Deploy Setup (IAM, EC2)
https://www.youtube.com/watch?v=qZa5JXmsWZs

GitHub for AWS tutorial video https://github.com/andrewpuch/code_deploy_example/

AWS CodeDeploy tutorial video https://www.youtube.com/watch?v=jcR9iIWdU7E

Steps to create running AWS EC2 instance


Create AWS free account

Getting started :
https://aws.amazon.com/free/

Create AWS account




Create own Linux instance
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html


Connect to AWS Linux instance via ssh

[dave@localhost aws]$ chmod 400 dave_amazon.pem
[dave@localhost aws]$ ssh -i "dave_amazon.pem" ec2-user@ec2-11-123-765-44.us-west-2.compute.amazonaws.com


       __|  __|_  )
       _|  (     /   Amazon Linux AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-ami/2016.03-release-notes/
8 package(s) needed for security, out of 17 available
Run "sudo yum update" to apply all updates.


Install AWS tools on Fedora

https://fedoramagazine.org/aws-tools-fedora/

[root@localhost ~]# dnf install  awscli
Dependencies resolved.
=================================================================================================
 Package                  Arch         Version                               Repository     Size
=================================================================================================
Installing:
 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": [
                {
                    "PublicDnsName":

Integrating AWS CodeDeploy with GitHub

https://docs.aws.amazon.com/codedeploy/latest/userguide/github-integ.html


Setup roles in IAM
https://docs.aws.amazon.com/codedeploy/latest/userguide/getting-started-setup.html



Amazon AWS Java samples
https://github.com/aws/aws-sdk-java/tree/master/src/samples



Create GitHub repository with sample application
https://github.com/dveselka/aws-java-sample

User guide GitHub - AWS integration
https://docs.aws.amazon.com/codedeploy/latest/userguide/github-integ-tutorial.html 

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


Connect with GitHub


Deploy AWS sample Linux
https://github.com/dveselka/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

https://docs.aws.amazon.com/codedeploy/latest/userguide/how-to-run-agent-install.html#how-to-run-agent-install-linux

[ec2-user@ip-172-31-21-129 ~]$ wget https://aws-codedeploy-eu-central-1.s3.amazonaws.com/latest/install
--2016-08-07 13:45:20--  https://aws-codedeploy-eu-central-1.s3.amazonaws.com/latest/install
Resolving aws-codedeploy-eu-central-1.s3.amazonaws.com (aws-codedeploy-eu-central-1.s3.amazonaws.com)... 54.231.193.44
Connecting to aws-codedeploy-eu-central-1.s3.amazonaws.com (aws-codedeploy-eu-central-1.s3.amazonaws.com)|54.231.193.44|: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 
189.278.189.245 - - [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
https://github.com/awslabs/aws-codedeploy-samples/tree/master/applications/SampleApp_Linux

Sample Tomcat application on GitHub
https://github.com/awslabs/aws-codedeploy-sample-tomcat


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

[dave@localhost aws]$ unzip -l SampleApp_Linux.zip 
Archive:  SampleApp_Linux.zip
  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

2 comments: