Integrate AWS CodeDeploy With Git And Deploy A Revision


Published on

Step by Step Implementation of How to Integrate AWS CodeDeploy With Git And Deploy A Revision

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Integrate AWS CodeDeploy With Git And Deploy A Revision

  1. 1. Integrate AWS CodeDeploy with Git and Deploy a Revision - Ishant Kumar
  2. 2. In these slides of DevOps Journey, we will demonstrate how to integrate Git with AWS CodeDeploy Service. What is AWS CodeDeploy? AWS CodeDeploy is an AWS service that coordinates application deployments to instances. Instances are groups of one or more Amazon EC2 instances or on-premises instances or both. (On-premises instances are physical devices that are not Amazon EC2 instances.) Source :
  3. 3. Reference :
  4. 4. Benefits : The benefit of Automated Deployment downtime can be minimized. Control your App Centralized Easy to use and adopt
  5. 5. Prerequisite : Create one EC2 instance with Amazon Linux AMI. Instance should be provisioned with below IAM Role as Instance need to download CodeDeploy Agent from S3 bucket. { “Version”: “2012-10-17″, “Statement”: [ { “Action”: [ “s3:Get*”, “s3:List*” ], “Effect”: “Allow”, “Resource”: “*” } ] }
  6. 6. Execute the below commands to configure and install codedeploy agent on the instance. sudo yum -y update sudo yum -y install ruby sudo yum -y install aws-cli cd /home/ec2-user aws s3 cp s3://aws-codedeploy-us-east-1/latest/install . –region us-east-1 chmod +x ./install sudo ./install auto
  7. 7. Now create one more Service role for CodeDeploy Service so that service should have EC2 Access. { “Version”: “yyyy-mm-dd”, “Statement”: [ { “Action”: [ “autoscaling:PutLifecycleHook”, “autoscaling:DeleteLifecycleHook”, “autoscaling:RecordLifecycleActionHeartbeat”, “autoscaling:CompleteLifecycleAction”, “autoscaling:DescribeAutoscalingGroups”, “autoscaling:PutInstanceInStandby”, “autoscaling:PutInstanceInService”, “ec2:Describe*” ], “Effect”: “Allow”, “Resource”: “*” } ] }
  8. 8. Replace the entire contents of the Policy Document box with the following policy, and then click Update Trust Policy: { “Version”: “2012-10-17″, “Statement”: [ { “Sid”: “”, “Effect”: “Allow”, “Principal”: { “Service”: [ “”,] }, “Action”: “sts:AssumeRole” } ] }
  9. 9. Directory Structure :
  10. 10. To Know How to setup Git on AWS EC2 , You can look our uploaded slide Setting up Git on AWS EC2 . Contents of file appspec.yml version: 0.0 os: linux files: – source: /index.html destination: /usr/share/nginx/html/ hooks: BeforeInstall: Continue….
  11. 11. Contents of file appspec.yml (continued …..) – location: scripts/install_dependencies timeout: 300 runas: root – location: scripts/start_server timeout: 300 runas: root ApplicationStop: – location: scripts/stop_server timeout: 300 runas: root
  12. 12. contents of file install_dependencies #!/bin/bash yum install -y nginx rm -f /usr/share/nginx/html/index.html Contents of file start_server #!/bin/bash service nginx start
  13. 13. Contents of file stop_server #!/bin/bash isExistApp = `pgrep nginx` if [[ -n $isExistApp ]]; then service nginx stop fi
  14. 14. Now lets start from here . Step 1 : SignIn to AWS console and select AWS CodeDeploy.
  15. 15. Step 2 : Click on get started Now.
  16. 16. Step 3 : Select custom Deployment and click on skip walk through.
  17. 17. Step 4: Create new Application by passing Application Name and Deployment Group Name.
  18. 18. Step 5 : Select instance(s) on which you want to deploy the code. (Instance(s) should have valid instance profile and code deploy agent installed).
  19. 19. Step 6 : Select service role ARN so that Code Deploy can access EC2. Role should have updated trust relationship. Click on Create Application.
  20. 20. Step 7 : Click on DemoDeploymentGroup Drop Down Arrow and click on Deploy New Revision.
  21. 21. Step 8: Select Your Application , Deployment Group and Revision Type. For Github , select “My Application is stored in Github” , and connect with Github by providing Github’s Username and password. Enter your user- name/Repository-name, comimit id of your latest code checkin and Deploy the Application.
  22. 22. Step 8: (continued ….)
  23. 23. Step 9 : Select Deployment id to check Application status.
  24. 24. Step 10 : You will see status succeeded if the deployment is successful. Click on events if you want to check the events performed.
  25. 25. Step 11 : Try hitting public ip of Instance. You will see below page. So this is how we can integrate AWS CodeDeploy with GitHub and can deploy the code with commit Id. If you want to deploy one more revision with updated code, pass the updated commit Id and Deploy the code.
  26. 26. Thanks Looking Forward for your interest in Email us: