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