1 00:00:08,090 --> 00:00:13,320 Welcome back to backspace Academy. In this hands-on lab on cloudformation 2 00:00:13,320 --> 00:00:19,140 we'll be using a premade cloudformation template to launch a LAMP which stands for 3 00:00:19,140 --> 00:00:27,480 Linux Apache mySQL PHP, a lamp environment on ec2. Then we will delete 4 00:00:27,480 --> 00:00:31,740 the cloudformation stack which will delete all of the resources that were 5 00:00:31,740 --> 00:00:39,300 created by cloudformation, first off we need to jump into the cloudformation console 6 00:00:39,300 --> 00:00:43,739 so again services and we select cloud formation from the 7 00:00:43,739 --> 00:00:49,680 management tools section, ok because we haven't created a stack before we're 8 00:00:49,680 --> 00:00:53,100 going to have this welcome screen, I'm just going to run through very quickly 9 00:00:53,100 --> 00:00:57,329 some of these options here so the first one it there is to just create a stack 10 00:00:57,329 --> 00:01:02,039 which is what we will be doing and that will launch an environment in a single region 11 00:01:02,039 --> 00:01:07,229 and then we put a stack set so this is a lot more advanced and we won't 12 00:01:07,229 --> 00:01:11,220 go into that but what you can do is actually create a stack set which will 13 00:01:11,220 --> 00:01:15,990 launch an environment in multiple regions and it can also do that in 14 00:01:15,990 --> 00:01:21,330 multiple AWS accounts as well we can design a template using the 15 00:01:21,330 --> 00:01:28,020 cloudformation designer and if you're going on to the AWS associate pathway through 16 00:01:28,020 --> 00:01:34,079 Backspace Academy then you will get a lot of work in using the 17 00:01:34,079 --> 00:01:39,060 cloudformation designer now that is a drag-and-drop graphical user interface 18 00:01:39,060 --> 00:01:43,409 where you can drag and drop items on, you know, ec2 servers and all this sort of stuff 19 00:01:43,409 --> 00:01:48,270 and link them using a graphical user interface and that's really good 20 00:01:48,270 --> 00:01:53,360 because you can actually see your environment how it all works and 21 00:01:53,360 --> 00:01:59,090 visualize it and then launch it directly from that graphical user user interface 22 00:01:59,090 --> 00:02:03,630 we can also create a template from our existing resources so we've already 23 00:02:03,630 --> 00:02:08,520 launched an ec2 instance and we have done a bit of work we can actually select 24 00:02:08,520 --> 00:02:11,840 those resources using a cloudformer tool 25 00:02:11,840 --> 00:02:16,970 and that will create a cloudformation template for us again we'll learn more 26 00:02:16,970 --> 00:02:22,040 about that in the pathway for the associate level but for now we are just 27 00:02:22,040 --> 00:02:26,090 going to be creating a stack in a single region, so we'll click on create new 28 00:02:26,090 --> 00:02:32,390 stack, so we're just going to select a sample template that has already been 29 00:02:32,390 --> 00:02:38,120 created by AWS, I'll select the single instant sample for a lamp stack don't 30 00:02:38,120 --> 00:02:42,049 select the multi AZ one because we don't want to create a multi AZ we we want to 31 00:02:42,049 --> 00:02:47,000 keep costs low here and what we can do is that before we launch all this we can 32 00:02:47,000 --> 00:02:52,190 actually have a look at the template in cloudformation designer, now I'll just 33 00:02:52,190 --> 00:02:57,950 click on that and that will launch the graphical user interface for 34 00:02:57,950 --> 00:03:01,730 cloudformation designer and so you can see we've got our web server which is our 35 00:03:01,730 --> 00:03:07,459 LAMP web server and then we've got a security group for that as well so we 36 00:03:07,459 --> 00:03:11,690 can click on these and it will show the actual part of the cloudformation 37 00:03:11,690 --> 00:03:16,190 template that that belongs to so I'm just going to maximize this now and you 38 00:03:16,190 --> 00:03:20,480 can see here we've got our web server security group and it's allowing traffic 39 00:03:20,480 --> 00:03:26,120 on port 80 which is HTTP which is what we want for a web server and it's also 40 00:03:26,120 --> 00:03:31,819 allowing us to connect in on port 22 for SSH is we want to connect in directly to 41 00:03:31,819 --> 00:03:37,220 the Linux operating system, so I just minimize that again and we can see here 42 00:03:37,220 --> 00:03:41,690 on the web server we can click on that and that will show our web server 43 00:03:41,690 --> 00:03:47,540 instance and we can see here it's it's an ec2 instance and it's got some stuff 44 00:03:47,540 --> 00:03:52,130 happening here don't worry too much about that but you just need to know 45 00:03:52,130 --> 00:03:57,590 that there is a resources for this cloud formation stack and the resources are 46 00:03:57,590 --> 00:04:04,790 the only part of a cloud formation template that are required, so we'll just 47 00:04:04,790 --> 00:04:10,730 jump back out of that and go back into leave, so unfortunately just 48 00:04:10,730 --> 00:04:15,169 put us back to where we started from, so again create a new stack we'll select it 49 00:04:15,169 --> 00:04:23,680 again and what we'll do is we'll go on to next we'll give this stack a name 50 00:04:24,700 --> 00:04:28,730 that will be fine we'll leave the database name as it is we'll put in a 51 00:04:28,730 --> 00:04:36,290 password so leave the password all just alphanumeric otherwise it'll be a bit of 52 00:04:36,290 --> 00:04:44,240 a problem and I'm just going to use admin for the user will select a t2 micro 53 00:04:44,240 --> 00:04:49,010 because we want this to be on the free tier and we should already have a key 54 00:04:49,010 --> 00:04:53,990 name because we've already used the ec2 it's service before so we should have a 55 00:04:53,990 --> 00:05:00,640 key name already we'll just select that one there and click on next 56 00:05:00,640 --> 00:05:04,910 okay so we've got some options here we can attach a tag so I'm going to attach 57 00:05:04,910 --> 00:05:09,920 a name tag to this and it has to be capital in and it'll come up in the list 58 00:05:09,920 --> 00:05:15,440 of ec2 instances when we create that instance and we can see it's good to 59 00:05:15,440 --> 00:05:20,570 give your resources a name tag so you can find them easy enough and I'm just 60 00:05:20,570 --> 00:05:26,780 going to give it the same name as the stack now if we created an iam role in 61 00:05:26,780 --> 00:05:31,400 this ec2 instance required and I am role we could attach that here or associate 62 00:05:31,400 --> 00:05:39,190 that here we also had rollback triggers so after a period of time if if the if 63 00:05:39,190 --> 00:05:44,600 the stack hasn't created correctly then it will be rolled back to what it was 64 00:05:44,600 --> 00:05:49,580 previously and so we can set that up if we like but we'll just leave that empty 65 00:05:49,580 --> 00:05:56,120 and we'll click on next and so there we can be review that there's no problems 66 00:05:56,120 --> 00:06:01,670 there and we click on create so what will happen is it'll go through and it 67 00:06:01,670 --> 00:06:05,630 will start to create that first off create that security group and then it 68 00:06:05,630 --> 00:06:09,530 will create that instance and launch that instance for us so if we click on 69 00:06:09,530 --> 00:06:14,540 the refresh icon up here we can see the status and there we can see we've got a 70 00:06:14,540 --> 00:06:19,190 lot of stuff going on here so it's already created that security group and 71 00:06:19,190 --> 00:06:27,200 it's in the process of creating that instance so it's going to take some time 72 00:06:27,200 --> 00:06:36,080 for that instance to launch okay so now it has the status of create complete so 73 00:06:36,080 --> 00:06:40,550 again you just keep the screen here and that should all be 74 00:06:40,550 --> 00:06:46,820 ready to go so if we now go to the ec2 service, so again go to services we 75 00:06:46,820 --> 00:06:52,550 select ec2 from the compute services we should be able to find this ec2 instance 76 00:06:52,550 --> 00:06:59,240 and here we go so we go to instances and then we can see is our test don't worry 77 00:06:59,240 --> 00:07:03,410 about the ones that I did previously but there we have our test let's see if that 78 00:07:03,410 --> 00:07:10,240 is up and running so what we can do now is that we can select this public DNS or 79 00:07:10,240 --> 00:07:15,020 we can select the public IP either one that is fine and we just go to that in 80 00:07:15,020 --> 00:07:19,030 our browser and see what happens and so there you go so we've actually 81 00:07:19,030 --> 00:07:26,840 successfully launched a PHP or a lamp stack and here we have a PHP application 82 00:07:26,840 --> 00:07:31,820 that is running on that so let's have a look at this in a bit more detail with 83 00:07:31,820 --> 00:07:36,980 this cloudformation stack so I'm just going to go back to the cloudformation 84 00:07:36,980 --> 00:07:44,840 management console, okay so in the management console we've got a number of 85 00:07:44,840 --> 00:07:48,860 tabs here that we can have a look at and so we're going to have a look at the 86 00:07:48,860 --> 00:07:53,960 template here and that will be the cloud formation template that we used to 87 00:07:53,960 --> 00:07:57,350 launch this stack so I'll have a look at that in a little bit more detail so 88 00:07:57,350 --> 00:08:00,860 we've obviously got a description here but we've also got this section called 89 00:08:00,860 --> 00:08:05,690 parameters now if you remember when we launched this stack it asked us to enter 90 00:08:05,690 --> 00:08:11,000 a lot of things so we had to select a key name for the ec2 instance we had to 91 00:08:11,000 --> 00:08:15,350 select we had to enter in a database name and the default there was my 92 00:08:15,350 --> 00:08:22,310 database and a DB user and a DB password so the parameters section is what we use 93 00:08:22,310 --> 00:08:28,370 to get information from the person that is launching that stack and it'll come 94 00:08:28,370 --> 00:08:33,020 up on the on the screen on the on the user interface when you're going through 95 00:08:33,020 --> 00:08:37,610 and launching that stack and then you can get that information and pass it on 96 00:08:37,610 --> 00:08:43,700 to cloud formation to make sure that the right work right ec2 instance type is 97 00:08:43,700 --> 00:08:47,720 launched and all that sort of thing so just going to scroll down a little bit 98 00:08:47,720 --> 00:08:51,110 further and so you can see here we've got the 99 00:08:51,110 --> 00:08:55,399 fault we've got the ec2 instance type and we've got t1 micro and all that and 100 00:08:55,399 --> 00:09:03,670 so we did we selected a t2 micro from memory and so we can sort t1 micro and 101 00:09:03,670 --> 00:09:09,320 we can do that so just scrolling down a bit more so 102 00:09:09,320 --> 00:09:13,190 we've actually got this section called mappings and so what that can do is it 103 00:09:13,190 --> 00:09:22,100 can map what we enter in a parameter to a another specific text so for example 104 00:09:22,100 --> 00:09:27,440 when you select t1 micro it's going to have a key for architecture so we have 105 00:09:27,440 --> 00:09:31,540 different types and you don't need to know about this too much but we have 106 00:09:31,540 --> 00:09:40,250 paravirtual and HVM so they're the two types of AMI and so depending on what 107 00:09:40,250 --> 00:09:46,550 instance you select decides whether you have paravirtual or hvm 108 00:09:46,550 --> 00:09:50,360 again don't be too concerned about it but there are a couple of types in 109 00:09:50,360 --> 00:09:55,519 and then from there we've got another set of mappings and so depending on 110 00:09:55,519 --> 00:10:01,310 whether you select US-East-1 or which other region you use we'll select 111 00:10:01,310 --> 00:10:08,480 a different AMI and also depending on what type of instance it is whether it's 112 00:10:08,480 --> 00:10:16,459 a paravirtual or HVM type but that will determine what AMI is selected for that 113 00:10:16,459 --> 00:10:22,519 instance so again don't be too concerned about PV and hvm just know that there 114 00:10:22,519 --> 00:10:29,029 are those two different types in but that's how we actually map the user 115 00:10:29,029 --> 00:10:37,220 input to something that cloudformation can understand and use so then we've got 116 00:10:37,220 --> 00:10:40,820 the most important section and the only compulsory section which is the 117 00:10:40,820 --> 00:10:45,500 resources section and so here we go we've got our ec2 instance and it's 118 00:10:45,500 --> 00:10:50,529 going to go through a lot of details around what to do with that instance and 119 00:10:50,529 --> 00:10:55,519 if we scroll down a little bit further we will find that we've got another 120 00:10:55,519 --> 00:11:00,440 resource which is our web server security group and again it's got some 121 00:11:00,440 --> 00:11:04,850 rules in for port 80 traffic to allow port 80 traffic to come 122 00:11:04,850 --> 00:11:11,000 because it's a web server and it's also got their port 22 if we want to connect 123 00:11:11,000 --> 00:11:16,639 in via SSH directly to that Linux operating system so these are the two 124 00:11:16,639 --> 00:11:22,040 resources that we are creating with this stack now finally we've got an output 125 00:11:22,040 --> 00:11:25,639 section so that's outputting something called 126 00:11:25,639 --> 00:11:31,160 website URL and it's got a description there and it's got a value there which 127 00:11:31,160 --> 00:11:39,649 has got the public DNS name so if you remember we use the public DNS name in 128 00:11:39,649 --> 00:11:45,920 our browser to view the finished website so where does it go this is information 129 00:11:45,920 --> 00:11:52,160 that we can present to a user that they may need to have so if we go to the 130 00:11:52,160 --> 00:11:57,709 outputs tab we can see there it is so there is our key which is website URL 131 00:11:57,709 --> 00:12:03,829 the value and the description which is exactly what we had in our cloud 132 00:12:03,829 --> 00:12:09,319 formation template so we had the website URL is a key we had a description for it 133 00:12:09,319 --> 00:12:14,509 and then we had the value which was the public DNS name plus it had HTTP in 134 00:12:14,509 --> 00:12:25,930 front of it as well so again if we open that it will point to what we got before 135 00:12:27,699 --> 00:12:35,779 so that's how AWS cloud formation works you define what you want from a 136 00:12:35,779 --> 00:12:40,339 user in the parameter section the user will input that you grab that and you 137 00:12:40,339 --> 00:12:44,990 pass it on to cloudformation and you create resources with that and then if 138 00:12:44,990 --> 00:12:48,829 you want any information to be fed back to the user you can create an output 139 00:12:48,829 --> 00:12:53,720 from your cloudformation stack, so what we need to do now is that we need to 140 00:12:53,720 --> 00:12:58,399 clean this all up so I'm just going to minimize this again and when you create 141 00:12:58,399 --> 00:13:03,019 a cloudformation stack it's very important that you don't delete the 142 00:13:03,019 --> 00:13:08,360 resources delete the stack and it will cleanly delete everything for you so we 143 00:13:08,360 --> 00:13:15,319 go into actions and we delete that stack yes delete and after a certain amount of 144 00:13:15,319 --> 00:13:18,899 time that will be finished and so we can just click on refresh here 145 00:13:18,899 --> 00:13:24,300 until it's done, so that brings us to the end of a reasonably 146 00:13:24,300 --> 00:13:28,649 complicated lab but I hope you've got a reasonable understanding of cloudformation 147 00:13:28,649 --> 00:13:32,189 and the different sections of a cloudformation template because 148 00:13:32,189 --> 00:13:36,629 that's well and truly all you would need to know as a cloud practitioner you 149 00:13:36,629 --> 00:13:41,790 don't need to know much about the nuts and bolts of an actual cloudformation 150 00:13:41,790 --> 00:13:47,550 template but rest assured if you go on to the associate level of this pathway 151 00:13:47,550 --> 00:13:52,559 then you'll certainly be getting very much involved in cloudformation I'll 152 00:13:52,559 --> 00:13:55,999 see you in the next lab