and welcome back to Backspace Academy in this hands-on lecture on creating a 2
custom ami we're going to be creating a node.js 3
server from scratch using the EC2 service so we're not going to be using a 4
pre-baked AMI so before we use the backspace nodejs ami we're going to be 5
making this from scratch so we're going to launch and ec2 Amazon Linux instance 6
and then we're going to put the software that we need on that instance and then 7
we're going to create an ami from that instance and then we'll use that ami to 8
launch another nodejs server and then we'll also look at copying this ami over 9
to another region so I'm just in the ec2 management console I'm just going to 10
quickly launch an instance using the Amazon Linux ami and that will be a tee 11
to micro instance and I need to make sure that we have a public IP address 12
assigned to this this instance the leaf storage and tags as they are but we need 13
to create a new security group it's going to call a test and I'll just leave 14
the description as it is here that's fine so we need to have SSH access 15
obviously to connect in and operate our instance so we'll leave that as a user 16
but we also need to have access from the wider internet to come in because it is 17
a web server that we're creating a node.js web server so we need to have 18
HTTP access on port 80 and that's for for everything to come in so now that 19
we've got those two rules set up we can review and launch and then launch our 20
instance we'll use a key pair that we've already got 21
if not we'll create one so this is launcher instance 22
now once our instance is up and running I'm just going to get the connection 23
command that I need so just click on connect after we have selected an 24
instance I'm just going to copy they can connection command here and use that in 25
a terminal screen to connect into this instance 26
ok so I've just opened a terminal screen and I've navigated to the location of my 27
key pairs that I'm using to connecting to this ec2 instance so I'm just going 28
to paste in that connection string and hopefully connecting and there we are if 29
connected in so the first thing I want to do with this Linux instance is to 30
update it so sudo yum update and - by just to say yes all the time 31
so after a certain amount of time we're going to have our you mate they 32
completed now the first thing we need to do is that we need to set up our Linux 33
firewall settings now being a NodeJS server it will be expecting, or the way 34
that we will set up our nodejs sample app is it will be expecting traffic to 35
come in on 8080 but our web traffic will be coming in on port 80 so what we need 36
to do is we need to set up IP forwarding from port 80 the traffic coming in and 37
forward that on to nodejs through the linux operating system to port 8080 and 38
then we need to enable port 80 access in our firewall setting so the first thing 39
we need to do is set up IP forwarding and we use that command there and that's the same 40
command that we used in the previous lesson on on creating a node.js 41
environment so just go back to the notes and you'll have that in those notes and 42
then accept traffic inbound on our port 80 and again there we put that in on our 43
output so there is our instances now set up in the Linux operating system to 44
accept traffic on port 80 it will redirect that traffic across to port 45
8080 to enable nodejs to receive that traffic. Now the 46
next thing we're going to do is we're going to install nodejs the latest 47
version of nodejs on this instance now I've provided a 48
link in this to the Amazon documentation that will explain how to go through and 49
do this so if you just go to the resources section and just click on that 50
link it'll link to the the JavaScript SDK documentation on nodejs that will 51
have that section on how to do this so I'm just going to paste it all in there 52
so first we do a call sort of curl and that is to install nvm or the node 53
version manager and that is what has happened then the next thing we need to 54
do is to activate that node version manager which we've done there and once 55
we have done that we can now install node and the latest version currently is 56
ace at the time of this video is being done so we're going to install nodejs 57
version 8 and there it is so we do node - - version it will tell us it 58
just installed version eight point two point one which is the latest version 59
out there that we can use for nodejs now the next thing we need to install is 60
Express so that we can create web page web pages so we do NPM install Express 61
and we'll do that globally now the next thing we're going to do is we're going 62
to need to install git so I'll put get on there as well so I just do a young 63
install git 64
check that's working so to git - - version and we can see we're like two 65
point seven point five set up there so that's fine so now that we've got get 66
set up what we're going to do is we're going to pull in the sample code that 67
we've got on the back space Academy site or on the back space technology github 68
account and so the we do a git clone and the addresses github.com 69
/backspaceTech and then /node - js - sample.git 70
so if you type that in that will clone that sample application and if we 71
just to a dir and we can have a look at more see than it is so there's our 72
node - js - sample application that has just been pulled in from that github 73
repository so I'm just now going to CD into that directory and we're just edit 74
look inside of it so the first thing I need to do in now is install the 75
packages that are needed for the application so we just do npm install 76
and that will pull in those NPM packages that we need that are defined in our 77
package JSON file so now we can run our applications so you can just do NPM 78
start if you want or if you want to see it in a debug output as well as just put 79
in this command there otherwise you just do npm start it'll both do the same 80
thing and we can see that it's listing on port 8080 so nodejs it'll now be 81
listening on port 8080 but the Linux operating system will be 82
accepting traffic on port 80 and we've also set up our security group to accept 83
traffic on port 80 as well so we should be able to now go to the public IP 84
address of this instance and we should be able to see our sample application 85
running okay so back in the ec2 management console I'm just going to 86
select that instance and I'm just going to select it to public IP address and go 87
to its public IP address and there we go we've got our sample application up and 88
so we've successfully launched in instance we've set up a security group 89
that is going to accept traffic on port 80 and we've also set up our Linux 90
instance with its firewall settings to redirect traffic from port 80 to port 91
8080 and also we have our no genius instance that we's accepting that 92
traffic and responding to that traffic as well and so there we have it so what 93
we'll do next is that we'll go back into the ec2 management console and we'll 94
create an ami of this ec2 instance now back in the ec2 management console we 95
just have to again select that instance and go to actions and then we go to 96
image and we can create an image of that 97
we'll give it a name okay so once we in there we just create the image down 98
okay so create image request receipt so we can click on the pending image so we 99
just go on here okay so after a certain amount of time our ami will have been 100
created and all have status available so what we can do if we go into permissions 101
so currently by default when we first create an ami it's going to be private 102
and so we can actually edit that and so we can change it to public so if we 103
change it to public and we say that it will then be available to be searched 104
for on the community AMIs so I'm just going to leave it private because I 105
don't want to put another ami there and get people confused when they're looking 106
for the backspace nodejs ami but if you wanted to create an application and you 107
wanted to put that ami out for the rest of the AWS community to use and that's 108
how you would do it you just make it a public AMI and it will be on there so 109
I'm just going to cancel out of that so what I'm going to look at doing now 110
is to copy this ami over to another region so I'm currently in North 111
Virginia and let's just say I want to copy it over to say Mumbai why not so 112
what I do is I go to actions copy ami and I select my destination region 113
Mumbai there we go and we have an option to encrypt that 114
I'm not going to worry about that and so I copy the ami over to Mumbai so cut 115
again comes up with a screen saying that this 116
operation is currently in progress so we can visit the ami in AP South one which 117
is a Mumbai region so let's have a look at that and see what's happening 118
it's going through the same thing it's going to be creating it will be pending 119
and then eventually go to available okay so after a bit longer amount of time to 120
doing it in the US East region to do a cross region copy tends to take a little 121
bit longer but we have our ami that was in the US east region is now being 122
copied over to the Mumbai region so if you want to create multiple instances in 123
multiple regions that are identical then this is how you do it you create an ami 124
and then you copy that ami over to the region that you want to launch into so 125
we can again we now that that's created we can launch an instance from here just 126
as soon as we will be four so I'm not going to go through that process now 127
simply because I haven't got a key pair set up for for connecting in but all you 128
would need to do is to go through and launch that instance again make sure 129
it's got a public IP address, launch that instance and make sure that you've 130
got a security group that will have access on port 22 and on port 80 and 131
then once that's up and running you can connect into it you can again set up 132
your IP forwarding in your Linux operating system and set up your 133
firewall settings in your Linux operating system to allow traffic on 134
port 80 and then you will be able to run that and run that application and you'll 135
be able to go to the IP address of that of that ec2 instance and you'll see the 136
application running so that brings us to the end of this lecture so you now have 137
a very good understanding of not only how the launch instances using ami but 138
also to launch an instance which is a bare-bones Linux operating system and 139
then go through and install software and create an ami of that finished ec2 140
instance then copy that over to multiple regions and launch ec2 instances that 141
are the same in multiple regions if you'd like so that brings us to the end 142
and I look forward to you in the next lecture