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