{"id":27240,"date":"2016-07-31T12:29:42","date_gmt":"2016-07-31T06:59:42","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=27240"},"modified":"2022-01-11T11:25:43","modified_gmt":"2022-01-11T05:55:43","slug":"aws-codedeploy-and-github","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/aws-codedeploy-and-github\/","title":{"rendered":"Deploy Code using AWS CodeDeploy and GitHub"},"content":{"rendered":"<p>The much talked about <a href=\"http:\/\/www.tothenew.com\/blog\/aws-code-deploy-a-sample-walkthrough\/\">AWS CodeDeploy<\/a> is being used as a daily deployment tool. According to AWS &#8220;AWS CodeDeploy coordinates application deployments to Amazon EC2 instances, on-premises instances, or both. (On-premises instances are physical devices that are not Amazon EC2 instances.)&#8221;<\/p>\n<p>On-premise support came in mid-2015. AWS CodeDeploy has been the choice of many since a long time and we are going to talk about it in this blog.<\/p>\n<h2>Use-case<\/h2>\n<p>I had to <a title=\"devops as a service\" href=\"http:\/\/www.tothenew.com\/devops-automation-consulting\">automate my deployment<\/a> process. I came across AWS CodeDeploy and it helped me to deploy my new code with ease and simplicity. We will go through the basic setup of CodeDeploy service, installation of CodeDeploy agent on a server (AWS EC2 instance) and deployment of new code from GitHub onto it. CodeDeploy is a region level service and in this, we will talk about deployment in the Virginia region. For using it in any other region, you have to make just a few changes in endpoints\u00a0which is simple too.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"\/blog\/wp-ttn-blog\/uploads\/2022\/01\/28.png\" alt=\"\" width=\"1876\" height=\"791\" class=\"aligncenter size-full wp-image-54511\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2022\/01\/28.png 1876w, \/blog\/wp-ttn-blog\/uploads\/2022\/01\/28-300x126.png 300w, \/blog\/wp-ttn-blog\/uploads\/2022\/01\/28-1024x432.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2022\/01\/28-768x324.png 768w, \/blog\/wp-ttn-blog\/uploads\/2022\/01\/28-1536x648.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2022\/01\/28-624x263.png 624w\" sizes=\"(max-width: 1876px) 100vw, 1876px\" \/><\/p>\n<h2>Prerequisites<\/h2>\n<ol>\n<li>An AWS EC2 instance with IAM role attached. If you don&#8217;t have a role attached to your EC2 instance, then you will have to launch a new EC2 instance with an attached role from an AMI. For now, you can just attach a blank role, and I will tell you later in the blog about what permissions policy to attach.<\/li>\n<li>Access to GitHub repository where the code is present<\/li>\n<li>AWS IAM role for the AWS CodeDeploy Service<\/li>\n<li>Appspec file and scripts which we will talk about shortly<\/li>\n<\/ol>\n<p>The above image shows the various stages and event hooks during a deployment using CodeDeploy. We define what CodeDeploy should do during all these events in a file called <strong>appspec.yml<\/strong> as mentioned in the prerequisites.<br \/>\nAppspec file needs some scripts along with it to work. Let&#8217;s look at a simple appspec.yml file:<\/p>\n<p>[js]<br \/>\nversion: 0.0<br \/>\nos: linux<br \/>\nfiles:<br \/>\n  &#8211; source: \/<br \/>\n    destination: \/home\/xxuserxx\/xxcodedirectoryxx<br \/>\nhooks:<br \/>\n  BeforeInstall:<br \/>\n    &#8211; location: apache_stop.sh<br \/>\n      timeout: 300<br \/>\n      runas: root<br \/>\n  AfterInstall:<br \/>\n    &#8211; location: afterinstall.sh<br \/>\n      timeout: 300<br \/>\n      runas: root<br \/>\n  ApplicationStart:<br \/>\n    &#8211; location: apache_start.sh<br \/>\n      timeout: 300<br \/>\n      runas: root<\/p>\n<p>[\/js]<\/p>\n<p>Above shown is the way you define various event hooks along with source ( the destination in the Git repository from where you want the code to be deployed, &#8220;\/&#8221; means the root directory of the repo) and destination ( the location on the server where the new code has to be placed). Each hook has a script associated with it.<br \/>\nLink to various Hooks:<\/p>\n<p>For this example, I have just used scripts for\u00a0<strong>BeforeInstall<\/strong>, <strong>AfterInstall<\/strong>, <strong>ApplicationStart<\/strong>.<\/p>\n<p><strong>BeforeInstall<\/strong>:<br \/>\nIn BeforeInstall I have used a script (apache_stop.sh) which will run before the install step i.e. before CodeDeploy puts the code to GitHub onto a node.<\/p>\n<p>[js]<br \/>\n#!\/bin\/bash<\/p>\n<p>#Stop apache service before deploying new code<br \/>\nservice apache2 stop<\/p>\n<p>mkdir -p \/home\/ubuntu\/code<br \/>\ntar -vczf \/home\/sap\/betasite-git-backup.`date`.tar.gz \/home\/xxuserxx\/xxcodedirectoryxx<br \/>\n#Copy current code to a directory<br \/>\n[\/js]<\/p>\n<p>This script will firstly clears the root directory where the older code is present. Reason being that CodeDeploy needs a clean directory where it has to deploy the code. Before cleaning the directory, it will also make a backup of the files. You can do any relevant changes in this step depending on your application like stop Apache or Tomcat etc. which would you need to do before the code is deployed.<\/p>\n<p>After this, the Install hooks is run by AWS CodeDeploy itself where it pulls the new code from the Git Repository and places it in the destination directory.<\/p>\n<p><strong>AfterInstall<\/strong>:<\/p>\n<p>Now, that CodeDeploy has placed the new code in the directory we asked it to, we can perform actions after it like compiling the code. For e.g. compiling CSS files or running some integrity tests:<\/p>\n<p>[js]<\/p>\n<p>cd \/home\/xxuserxx\/xxcodedirectoryxx<br \/>\nnpm install<\/p>\n<p>#GULP COMMANDS<br \/>\ngulp scss<br \/>\ngulp cpk-scss<br \/>\ngulp compile<\/p>\n<p>[\/js]<\/p>\n<p><strong>ApplicationStart<\/strong>:<\/p>\n<p>Here, I have simply added a command that will start apache and check whether it is running or not. If Apache fails to start, obviously there are some code issues, and you will be shown an error on the console.<\/p>\n<p>[js]<br \/>\n#!\/bin\/bash<\/p>\n<p>service apache2 restart<br \/>\n[\/js]<\/p>\n<p>Now, that we have the appspec.yml and the scripts handy, just push it along with the code to GitHub.<br \/>\nRemember, <strong>appspec.yml<\/strong> should be present in the root directory of your code. and \u00a0the scripts in a folder named scripts and location of scripts should be correct in <strong>appspec.yml<\/strong><\/p>\n<h3>One more important thing before we move onto the console:<\/h3>\n<p>AWS CodeDeploy needs a role to be able to access your AWS EC2 instances. Go to IAM and create a role having the following policy:<\/p>\n<div id=\"crayon-54fafd12bc7dd377388229-1\" class=\"crayon-line\">\n<div>\n<div id=\"highlighter_506498\" class=\"syntaxhighlighter  jscript\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<div class=\"line number8 index7 alt1\">8<\/div>\n<div class=\"line number9 index8 alt2\">9<\/div>\n<div class=\"line number10 index9 alt1\">10<\/div>\n<div class=\"line number11 index10 alt2\">11<\/div>\n<div class=\"line number12 index11 alt1\">12<\/div>\n<div class=\"line number13 index12 alt2\">13<\/div>\n<div class=\"line number14 index13 alt1\">14<\/div>\n<div class=\"line number15 index14 alt2\">15<\/div>\n<div class=\"line number16 index15 alt1\">16<\/div>\n<div class=\"line number17 index16 alt2\">17<\/div>\n<div class=\"line number18 index17 alt1\">18<\/div>\n<div class=\"line number19 index18 alt2\">19<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"jscript plain\">{<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"jscript string\">\"Version\"<\/code><code class=\"jscript plain\">: <\/code><code class=\"jscript string\">\"2012-10-17\"<\/code><code class=\"jscript plain\">,<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"jscript spaces\">\u00a0<\/code><code class=\"jscript string\">\"Statement\"<\/code><code class=\"jscript plain\">: [<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"jscript spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"jscript plain\">{<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"jscript spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"jscript string\">\"Action\"<\/code><code class=\"jscript plain\">: [<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"jscript spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"jscript string\">\"autoscaling:PutLifecycleHook\"<\/code><code class=\"jscript plain\">,<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"jscript spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"jscript string\">\"autoscaling:DeleteLifecycleHook\"<\/code><code class=\"jscript plain\">,<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"jscript spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"jscript string\">\"autoscaling:RecordLifecycleActionHeartbeat\"<\/code><code class=\"jscript plain\">,<\/code><\/div>\n<div class=\"line number9 index8 alt2\"><code class=\"jscript spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"jscript string\">\"autoscaling:CompleteLifecycleAction\"<\/code><code class=\"jscript plain\">,<\/code><\/div>\n<div class=\"line number10 index9 alt1\"><code class=\"jscript spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"jscript string\">\"autoscaling:DescribeAutoscalingGroups\"<\/code><code class=\"jscript plain\">,<\/code><\/div>\n<div class=\"line number11 index10 alt2\"><code class=\"jscript spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"jscript string\">\"autoscaling:PutInstanceInStandby\"<\/code><code class=\"jscript plain\">,<\/code><\/div>\n<div class=\"line number12 index11 alt1\"><code class=\"jscript spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"jscript string\">\"autoscaling:PutInstanceInService\"<\/code><code class=\"jscript plain\">,<\/code><\/div>\n<div class=\"line number13 index12 alt2\"><code class=\"jscript spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"jscript string\">\"ec2:Describe*\"<\/code><\/div>\n<div class=\"line number14 index13 alt1\"><code class=\"jscript spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"jscript plain\">],<\/code><\/div>\n<div class=\"line number15 index14 alt2\"><code class=\"jscript spaces\">\u00a0\u00a0<\/code><code class=\"jscript string\">\"Effect\"<\/code><code class=\"jscript plain\">: <\/code><code class=\"jscript string\">\"Allow\"<\/code><code class=\"jscript plain\">,<\/code><\/div>\n<div class=\"line number16 index15 alt1\"><code class=\"jscript spaces\">\u00a0\u00a0<\/code><code class=\"jscript string\">\"Resource\"<\/code><code class=\"jscript plain\">: <\/code><code class=\"jscript string\">\"*\"<\/code><\/div>\n<div class=\"line number17 index16 alt2\"><code class=\"jscript spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"jscript plain\">}<\/code><\/div>\n<div class=\"line number18 index17 alt1\"><code class=\"jscript spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"jscript plain\">]<\/code><\/div>\n<div class=\"line number19 index18 alt2\"><code class=\"jscript spaces\">\u00a0<\/code><code class=\"jscript plain\">}<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>With this, the <strong>Trust Relationship<\/strong> also needs to be changed in IAM, and that should now be as follows:<\/p>\n<div class=\"line number1 index0 alt2\">\n<p>[js]<br \/>\n{<br \/>\n&amp;quot;Version&amp;quot;: &amp;quot;2012-10-17&amp;quot;,<br \/>\n&amp;quot;Statement&amp;quot;: [<br \/>\n{<br \/>\n&amp;quot;Sid&amp;quot;: &amp;quot;1&amp;quot;,<br \/>\n&amp;quot;Effect&amp;quot;: &amp;quot;Allow&amp;quot;,<br \/>\n&amp;quot;Principal&amp;quot;: {<br \/>\n&amp;quot;Service&amp;quot;: [<br \/>\n&amp;quot;codedeploy.us-west-2.amazonaws.com&amp;quot;,<br \/>\n&amp;quot;codedeploy.us-east-1.amazonaws.com&amp;quot;<br \/>\n]<br \/>\n},<br \/>\n&amp;quot;Action&amp;quot;: &amp;quot;sts:AssumeRole&amp;quot;<br \/>\n}<br \/>\n]<br \/>\n}<br \/>\n[\/js]<\/p>\n<p>Now, as I told you above in the prerequisites that the Instances on which we need to deploy the new code needs an IAM role attached to it along with a CodeDeploy agent installed on it. The policy that needs to be given to the role is:<\/p>\n<p>[js]<br \/>\n { &amp;quot;Statement&amp;quot;:[<br \/>\n  {&amp;quot;Resource&amp;quot;:&amp;quot;*&amp;quot;,<br \/>\n  &amp;quot;Action&amp;quot;: [&amp;quot;autoscaling:Describe*&amp;quot;,&amp;quot;cloudformation:Describe*&amp;quot;,&amp;quot;s3:Get*&amp;quot;],<br \/>\n  &amp;quot;Effect&amp;quot;:&amp;quot;Allow&amp;quot;}] }<br \/>\n[\/js]<\/p>\n<p>and Trust Relationship would be:<\/p>\n<p>[js]{<br \/>\n&amp;quot;Version&amp;quot;: &amp;quot;2012-10-17&amp;quot;,<br \/>\n&amp;quot;Statement&amp;quot;: [<br \/>\n{<br \/>\n&amp;quot;Sid&amp;quot;: &amp;quot;&amp;quot;,<br \/>\n&amp;quot;Effect&amp;quot;: &amp;quot;Allow&amp;quot;,<br \/>\n&amp;quot;Principal&amp;quot;: {<br \/>\n&amp;quot;Service&amp;quot;: &amp;quot;ec2.amazonaws.com&amp;quot;<br \/>\n},<br \/>\n&amp;quot;Action&amp;quot;: &amp;quot;sts:AssumeRole&amp;quot;<br \/>\n}<br \/>\n]<br \/>\n}[\/js]<\/p>\n<p>Let&#8217;s install the CodeDeploy agent on the node\/nodes now by following the below steps:<\/p>\n<p>[js]sudo apt-get update<br \/>\nsudo apt-get install awscli<br \/>\nsudo apt-get install ruby2.0<br \/>\ncd \/home\/ubuntu<br \/>\nsudo aws s3 cp s3:\/\/aws-codedeploy-us-east-1\/latest\/install . &#8211;region us-east-1<br \/>\nsudo chmod +x .\/install<br \/>\nsudo .\/install auto<br \/>\n[\/js]<\/p>\n<h2>CONSOLE STEPS<\/h2>\n<h3>Steps to perform in the AWS CodeDeploy Console:<\/h3>\n<p>1. Go to AWS CodeDeploy and Select on Create New Application:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-37951\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/Screenshot-from-2016-07-22-120039.png\" alt=\"Screenshot from 2016-07-22 12:00:39\" width=\"952\" height=\"259\" \/><\/p>\n<p>The above will take you to the following page where you need to give a name to your application and enter <strong>Deployment Group Name <\/strong>and\u00a0<strong>Deployment Group<\/strong> is a subset of an Application where we add instances on which we want to deploy the code.\u00a0:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-38828\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/Screenshot-from-2016-07-30-235426.png\" alt=\"Screenshot from 2016-07-30 23:54:26\" width=\"881\" height=\"213\" \/><\/p>\n<p>2. Next, choose the Tag you want to use to filter instances to add to a <strong>Deployment Group<\/strong>. We can have different Deployment Groups within a single application. We can make another Deployment\u00a0Group later if needed and deploy different code on both of them. In a single deployment you can deploy code only to one Deployment Group:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-37950\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/Screenshot-from-2016-06-07-02_38_07.png\" alt=\"Screenshot from 2016-06-07 02_38_07\" width=\"1113\" height=\"251\" \/><\/p>\n<p>Once that is done, we need to deploy the new code and let CodeDeploy know from where it has to pick up the code and deploy to the deployment group demo that has instance code_deploy_test in it.<\/p>\n<p>3. Next, you can configure the deployment Config (which is an input that tells code deploy about the deployment strategy when you have more than one servers where the code will be deployed):<br \/>\nFor e.g., Deploy code to one server at a time:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-38829\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/Screenshot-from-2016-07-30-235520.png\" alt=\"Screenshot from 2016-07-30 23:55:20\" width=\"824\" height=\"469\" \/><br \/>\nYou have other options as well:<br \/>\n<strong>Deploy Half at once<\/strong>: Deploys to exactly half of the servers at a time.<br \/>\n<strong>Deploy All at once<\/strong>: Deploys to all servers at once.<br \/>\nI prefer one at a time as any error if there is one can be detected early rather than after new code is already deployed to all the servers.<\/p>\n<p>Along with that, you can also create any triggers using &#8220;Create trigger&#8221;. A simple use-case could be triggering an SNS notification which in turn could perform an action. When you click on create trigger, you would see something like:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-38832\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/Screenshot-from-2016-07-30-235952.png\" alt=\"Screenshot from 2016-07-30 23:59:52\" width=\"626\" height=\"582\" \/><\/p>\n<p>Following\u00a0are the events triggers that CodeDeploy supports:<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-38831\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/Screenshot-from-2016-07-31-000007.png\" alt=\"Screenshot from 2016-07-31 00:00:07\" width=\"629\" height=\"372\" \/><br \/>\nAfter selecting the event just mention the SNS topic and create the trigger. You can create multiple triggers.<\/p>\n<p>After all that is done, just create the application by clicking on <strong>Create Application<\/strong>:<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-38833\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/codedeploy-img-1.png\" alt=\"codedeploy-img-1\" width=\"831\" height=\"233\" \/><\/p>\n<p>4. Once that is done, you will be directed to a new page, and you should see a message like:<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-38863\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/Screenshot-from-2016-07-31-152831.png\" alt=\"Screenshot from 2016-07-31 15:28:31\" width=\"1285\" height=\"323\" \/><\/p>\n<p>On the same page, you will see <strong>Deployment Groups<\/strong> and <strong>Revisions:<\/strong><br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-38864\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/Screenshot-from-2016-07-31-15-32-57.png\" alt=\"Screenshot from 2016 07 31 15 32 57\" width=\"1241\" height=\"639\" \/><br \/>\nYou can create a new Deployment Group by clicking on &#8220;<strong>Create deployment group<\/strong>&#8220;. &#8220;<strong>Revisions<\/strong>&#8221;\u00a0shows the number of times the code was deployed to this Deployment Group which of course is zero for now. If you have multiple Deployment Groups, just select it and then click on Revisions which will expand any previous deployment details. You can also revert to a previous revision of code by selecting the revision and deploying it to the Deployment Group again. All that said, let&#8217;s do our first AWS CodeDeploy deployment.<\/p>\n<p>5. Select the Deployment Group and then go to &#8220;<strong>Actions<\/strong>&#8221; to select &#8220;<strong>Deploy new revision<\/strong>&#8220;:<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-38865\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/Screenshot-from-2016-07-31-15-40-44.png\" alt=\"Screenshot from 2016 07 31 15 40 44\" width=\"1190\" height=\"222\" \/><\/p>\n<p>This will take you to a new page which will look something like:<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-38867\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/Screenshot-from-2016-07-31-15-45-21.png\" alt=\"Screenshot from 2016 07 31 15 45 21\" width=\"638\" height=\"438\" \/><br \/>\nYou just need to choose the application, and it&#8217;s respective Deployment Group and GitHub in Revision Type. Once you do that, just select &#8220;<strong>Connect with GitHub<\/strong>&#8220;. Doing that will pop up a new browser window, take you to GitHub login where you will have to enter your username and password. After that come back to this page, and you should see something like below. Just enter the remaining details and click &#8220;<strong>Deploy Now<\/strong>&#8220;:<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-38869\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/Screenshot-from-2016-07-31-15-56-28.png\" alt=\"Screenshot from 2016 07 31 15 56 28\" width=\"651\" height=\"544\" \/><\/p>\n<p>This will take you to a page as follows:<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-38870\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/Screenshot-from-2016-07-31-16-02-16.png\" alt=\"Screenshot from 2016 07 31 16 02 16\" width=\"1234\" height=\"381\" \/><br \/>\nHere you will see details of your current deployment like <strong>Deployment ID<\/strong>, <strong>Application<\/strong>, <strong>Deployment Group<\/strong>, <strong>Revision Location<\/strong>, <strong>Start Time<\/strong>, <strong>End Time<\/strong>, <strong>Status<\/strong>, <strong>Actions<\/strong>.\u00a0You can stop your deployment from under the Actions by clicking on <strong>STOP.\u00a0<\/strong>To view the live progress of the deployment just click on the Deployment ID and it will take you to the details page where you will be able to see all the hooks being performed one by one. If the deployment is successfully completed you will see something below on the same page:<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-38871\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/Screenshot-from-2016-07-22-11_37_42.png\" alt=\"Screenshot from 2016-07-22 11_37_42\" width=\"1249\" height=\"300\" \/><\/p>\n<p>6. For a successful job CodeDeploy usually does not give logs but just in case your deployment failed at any step, \u00a0you can go ahead, check the error log by clicking on &#8220;<strong>View Logs&#8221;<\/strong>, and by clicking on View in EC2 it will do nothing but take you to the AWS EC2 Management Console where and filter out the servers of the deployment group. You can ssh into the servers and check the logs in &#8220;\/var\/log\/&#8217; directory. The below image shows what you would see during an error:<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-38873\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/Screenshot-from-2016-07-31-16-20-39.png\" alt=\"Screenshot from 2016 07 31 16 20 39\" width=\"1247\" height=\"80\" \/><br \/>\nRemember you can&#8217;t start a deployment again from here itself. You need to go to Deployment Groups page and deploy a new revision.<\/p>\n<p>So, this is how CodeDeploy works and how you can deploy your code easily using CodeDeploy on n number of servers.<\/p>\n<p>You can perform all the above console steps via AWS CLI as well. Read more about it here: <a href=\"http:\/\/docs.aws.amazon.com\/cli\/latest\/reference\/deploy\/index.html\" target=\"_blank\" rel=\"noopener\">AWS CodeDeploy CLI<\/a>.<br \/>\nFor now, automatic rollback is not provided as a feature, and you have to deploy a previous revision through the console manually. To get rid of that, we at TO THE NEW have been able to <a title=\"devops in aws\" href=\"http:\/\/www.tothenew.com\/devops-aws\">automate that using AWS Lambda<\/a>. You can read about that use-case here: <a title=\"Automatic Rollback in AWS CodeDeploy\" href=\"http:\/\/www.tothenew.com\/blog\/aws-codedeploy-automatic-rollback-using-aws-lambda\/\" target=\"_blank\" rel=\"noopener\">Automatic Rollback in AWS CodeDeploy<\/a>.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The much talked about AWS CodeDeploy is being used as a daily deployment tool. According to AWS &#8220;AWS CodeDeploy coordinates application deployments to Amazon EC2 instances, on-premises instances, or both. (On-premises instances are physical devices that are not Amazon EC2 instances.)&#8221; On-premise support came in mid-2015. AWS CodeDeploy has been the choice of many since [&hellip;]<\/p>\n","protected":false},"author":174,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":38},"categories":[1174,2348,1],"tags":[248,1676,3884,3878,3879,3881,3883,3880,3877,3882],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/27240"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/174"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=27240"}],"version-history":[{"count":1,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/27240\/revisions"}],"predecessor-version":[{"id":54512,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/27240\/revisions\/54512"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=27240"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=27240"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=27240"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}