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