1 00:00:06,950 --> 00:00:12,450 Welcome back to BackSpace Academy. In this lecture on continuous 2 00:00:12,450 --> 00:00:17,760 integration and continuous delivery, we're going to be creating a CI CD 3 00:00:17,760 --> 00:00:24,330 pipeline using AWS Codepipeline. First off we're going to be creating an 4 00:00:24,330 --> 00:00:30,150 Elastic Beanstalk highly available and fault tolerant environment for deploying 5 00:00:30,150 --> 00:00:35,160 our nodejs web application. Once we've done that 6 00:00:35,160 --> 00:00:40,890 we're going to create a Github repository that is going to contain a 7 00:00:40,890 --> 00:00:47,280 Nodejs application and we're going to integrate between that Github repository 8 00:00:47,280 --> 00:00:53,879 and our Elastic Beanstalk environment, so that whenever we change that code in the 9 00:00:53,879 --> 00:01:01,109 Github repository it will automatically update and deploy our changes to that 10 00:01:01,109 --> 00:01:08,610 environment. Our AWS Codepipeline will consist of a number of sub processes. 11 00:01:08,610 --> 00:01:13,619 We will start off with our source code and in this lab it will be located in a 12 00:01:13,619 --> 00:01:20,159 Github repository. It could also be located in an AWS Codecommit repository 13 00:01:20,159 --> 00:01:25,259 which is AWS implementation of Git. It could be in an 14 00:01:25,259 --> 00:01:31,740 Amazon s3 bucket or it could also be a Docker image in the Elastic Container 15 00:01:31,740 --> 00:01:38,670 Registry as well. Once we've done that we can build our application using AWS 16 00:01:38,670 --> 00:01:43,950 Codebuild or a number of other different build environments. Once our application 17 00:01:43,950 --> 00:01:49,200 has been built we can then test it. We can use a number of different 18 00:01:49,200 --> 00:01:53,790 environments to do that as well. Once we've tested it and it's past that 19 00:01:53,790 --> 00:02:00,240 staging with testing, it can then go on to be a production deployment. 20 00:02:00,240 --> 00:02:04,740 We would use AWS code deploy or in this lab we're going to be using a direct 21 00:02:04,740 --> 00:02:11,340 deployment to an AWS Elastic Beanstalk Environment. Now for this lab 22 00:02:11,340 --> 00:02:16,590 we're just going to be going from our source and integrating that with our 23 00:02:16,590 --> 00:02:21,209 production environment which we're going to create on Elastic Beanstalk which 24 00:02:21,209 --> 00:02:24,360 will be a highly available and fault tolerant architecture there for 25 00:02:24,360 --> 00:02:29,400 deploying that Nodejs web application. We're just going to integrate that 26 00:02:29,400 --> 00:02:34,500 with our Github repository so that when we make changes to our Github repository 27 00:02:34,500 --> 00:02:42,239 they will be automatically pushed through to our deployed environment. 28 00:02:42,239 --> 00:02:45,900 The first thing that we need to do is that we need to get hold of this node.js 29 00:02:45,900 --> 00:02:50,250 code that we're going to be using to deploy on this Elastic Beanstalk 30 00:02:50,250 --> 00:02:54,330 environment. What we need to do is go to the Backspace Academy site and go to 31 00:02:54,330 --> 00:03:00,209 this AWS NodeJS Elastic Beanstalk sample application that I've created here. 32 00:03:00,209 --> 00:03:11,269 What you want to do to star it and fork it and that will fork it in to your 33 00:03:11,269 --> 00:03:19,260 Github repository. Once that's done what I want you to do now is just 34 00:03:19,260 --> 00:03:25,739 download that. We just download that zip file. Okay, so once that's 35 00:03:25,739 --> 00:03:32,640 downloaded we can see here that all of our code is located inside of a 36 00:03:32,640 --> 00:03:36,239 directory. So that's no good for us. What we need to do is that we need to 37 00:03:36,239 --> 00:03:40,560 have our repository look like that. We can't have all of our files hidden 38 00:03:40,560 --> 00:03:50,670 inside a folder there. What we need to do first of all is extract this. 39 00:03:50,670 --> 00:03:57,120 That's unzipped, so just open that up. Now before we rezip this and upload it 40 00:03:57,120 --> 00:04:02,519 to Elastic Beanstalk environment, I want to actually change the background 41 00:04:02,519 --> 00:04:08,970 of this web page, so that when we first have deployed it has for example a blue 42 00:04:08,970 --> 00:04:16,709 background and then when we integrate our Github repository with this Elastic 43 00:04:16,709 --> 00:04:19,889 Beanstalk environment and we make any changes here, we can see that the color 44 00:04:19,889 --> 00:04:24,210 has actually changed. What we do is we go into our static directory here. 45 00:04:24,210 --> 00:04:28,259 We go into App and CSS. We're going to open up this 46 00:04:28,259 --> 00:04:37,259 app.css. Okay so there we can see that background color is lime and I'm 47 00:04:37,259 --> 00:04:46,979 just going to change that to light sky blue. I'll just save that. 48 00:04:46,979 --> 00:04:50,460 What we can do now is that we can zip everything back up again. We make sure 49 00:04:50,460 --> 00:04:55,740 that we we don't have everything hidden here in a directory we have it all 50 00:04:55,740 --> 00:05:06,930 looking like this. Then we can just zip all that up and that will be fine. 51 00:05:06,930 --> 00:05:10,759 That is our package there app.zip that we're going to upload to our 52 00:05:10,759 --> 00:05:17,879 Elastic Beanstalk environment. Just very quickly before we jump on to the 53 00:05:17,879 --> 00:05:23,460 Elastic Beanstalk part of the lab, I just want to talk about some of the files 54 00:05:23,460 --> 00:05:29,099 that are here. What we've got here is an EB.extensions folder. That is 55 00:05:29,099 --> 00:05:34,110 where we put our configurations that we want Elastic 56 00:05:34,110 --> 00:05:38,580 Beanstalk to read. Let's have a look at that. Just open that up and we'll 57 00:05:38,580 --> 00:05:46,229 have a look at this options.config. Here we can 58 00:05:46,229 --> 00:05:51,330 see that we've got some options that we want to pass 59 00:05:51,330 --> 00:05:56,300 through to Elastic Beanstalk. The first one there is that we've got the 60 00:05:56,300 --> 00:06:02,759 environment variable for AWS region. What that means is that Elastic 61 00:06:02,759 --> 00:06:08,659 Beanstalk will deploy this deployment environment to a region and 62 00:06:08,659 --> 00:06:16,560 our application is not going to know what region it actually is in, so if 63 00:06:16,560 --> 00:06:22,379 we're using the software development kit, part of that initialization process of 64 00:06:22,379 --> 00:06:25,110 the software development kit is that you will need to tell the software 65 00:06:25,110 --> 00:06:30,330 development kit exactly what region you are operating in. This is a great way 66 00:06:30,330 --> 00:06:34,169 to do it because you can just have that environment variable, and we'll have a 67 00:06:34,169 --> 00:06:37,559 look at that in the code in a second, 68 00:06:37,559 --> 00:06:41,159 and we can have Elastic Beanstalk pass that to your application as an 69 00:06:41,159 --> 00:06:45,659 environment variable. The next thing we want to do is we want to tell Elastic 70 00:06:45,659 --> 00:06:50,219 Beanstalk that it's going to be a Nodejs application and, it's going to be using 71 00:06:50,219 --> 00:06:59,819 the Nginx web server to deploy this and, it's going to be proxying static files 72 00:06:59,819 --> 00:07:06,059 that will be located in a static folder there. Our Nodejs application won't 73 00:07:06,059 --> 00:07:10,799 actually be delivering the static files or the pictures and libraries and all 74 00:07:10,799 --> 00:07:17,189 this sort of stuff, they'll be delivered directly by the Nginx web server. 75 00:07:17,189 --> 00:07:28,379 Let's jump into the actual code. We go back to the main area here and if we go 76 00:07:28,379 --> 00:07:32,239 to app.js and have a look at that. 77 00:07:40,960 --> 00:07:45,479 Okay so you can see what's going on here. First of all where we're loading that 78 00:07:45,479 --> 00:07:51,880 AWS software development kit. Now if you're not a developer don't worry too 79 00:07:51,880 --> 00:07:56,530 much about this you can still kind of understand what's going on, but part of 80 00:07:56,530 --> 00:08:01,960 this when we use the AWS software development kit, we need to tell it what 81 00:08:01,960 --> 00:08:07,440 region we are in. There's AWS.config.region and we're referencing a 82 00:08:07,440 --> 00:08:13,680 process environment variable called region. That is what is passed from 83 00:08:13,680 --> 00:08:19,449 the Elastic Beanstalk service and then we can see is just a standard Nodejs 84 00:08:19,449 --> 00:08:24,400 Express web application. If you're a developer you would have seen something 85 00:08:24,400 --> 00:08:31,030 like this numerous times. So without further ado let's jump into Elastic 86 00:08:31,030 --> 00:08:37,899 Beanstalk and start deploying this. Okay starting off in the management 87 00:08:37,899 --> 00:08:47,680 console we go to services Elastic Beanstalk. We create a new 88 00:08:47,680 --> 00:08:58,180 application, top right hand corner here. We'll give our application a name and 89 00:08:58,180 --> 00:09:04,990 create. Ok so our application has been created we just need to create the 90 00:09:04,990 --> 00:09:11,110 environment now. We go to actions and create environment. We want 91 00:09:11,110 --> 00:09:17,830 to create a web server environment. We will leave the environment name as it is. 92 00:09:17,830 --> 00:09:24,430 Our platform is going to be NodeJS. We're going to be uploading our own code so we 93 00:09:24,430 --> 00:09:32,320 click on upload. We'll select our local file for that. Ok so after five 94 00:09:32,320 --> 00:09:37,839 minutes or so we have our Elastic Beanstalk environment up and running. 95 00:09:37,839 --> 00:09:44,230 We can check that everything's fine by clicking on the environment URL. 96 00:09:44,230 --> 00:09:48,760 Just click on that now. We can see there we have a NodeJS web application. 97 00:09:48,760 --> 00:09:53,860 It has a light sky-blue background which we defined in our CSS file. 98 00:09:53,860 --> 00:09:58,570 Coming up next, what we're going to do now is that we're going to 99 00:09:58,570 --> 00:10:06,160 link a Github repository to this Elastic Beanstalk environment using AWS Codepipeline. 100 00:10:06,160 --> 00:10:12,060 So I look forward to seeing you in that one.