Welcome back to Backspace Academy. In this lecture on cloud formation we're 2
going to look into a lot more detail the different sections of a cloudformation 3
template then we'll look at stack sets into a bit more detail and then cloudformer 4
and finally we'll finish up with cloudformation designer, so let's have a 5
look in a little bit more detail the different sections of a cloudformation 6
template so at the start we're going to have that format version which will be 7
the version of the cloudformation interpreter that our code conforms to 8
then we're obviously going to have a description must follow the format 9
version then we can add metadata which will be JSON objects that are just there 10
to provide additional information if we need to so we should already know that 11
parameters allow values to be passed at state creation and we can supply a 12
default parameter for the situation where a parameter has not been supplied 13
so here we can see an example of the parameters section so here it's looking 14
for the instance type to be entered in from a user it will be looking for a 15
string and the default will be t2 micro and the allowed values there will be 16
those three of micro small and large and there'll be description they're saying 17
enter T2 micro or whatever so what will happen is that when someone goes to 18
launch this cloud formation stack a message will come up saying enter 19
t2 micro m1 small or M1 large and it will be by default selected as t2 micro 20
but there will be a drop down list there that the user can select from if they 21
want to go for an M1 small or an M1 large. Mappings match keys to 22
corresponding name value pairs and in the example they we've got a mapping 23
section which has a region map and that's going to map the region that is 24
selected to the correct ami and we've got two options there of a 32 or a 25
64-bit AMI so we can refer to regionmap in our 26
resources so there we can see in air resources 27
got an ec2 instance and the image ID is looking it's using a function find in 28
map and the map is regionmap and it's looking for the AWS region that we 29
selected so if we selected us east it'll select one of those 32 or 64 and then 30
the next line is is selecting for a 32-bit option so we'll select that first 31
to AMI there are two types of transforms that can be applied to a cloudformation 32
template the first one there being serviced and that defines the serverless 33
application model being used if this is specifically for a deployment of a 34
serverless application and then the next one is include which allows you to 35
include code snippets that could be stored in an Amazon s3 bucket 36
so there we can see we've got a resources section there that has properties for a Amazon 37
s3 bucket and those properties are using a function transform and so what that is 38
going to do it's going to include properties from a bucket location and so 39
that bucket location there is going to be the bucket name and there's another 40
one there for the bucket access control list as well and so those that code in 41
those two files will be included into your cloud formation template conditions 42
define the conditions around when a resource can be created or a property 43
defined so let's have a look at this here so we've got some parameters here 44
that are going to be entered and one of those parameters is going to be the 45
environment type and so that's going to be either prod or tests are there 46
allowed values and then we've got a condition and that is called create 47
products or tsa's now that condition will be true if the environment type 48
equals prod now if we go into our resources we can 49
see that we've got an ec2 instance and the ec2 instance mount point is a volume 50
attachment now we are not going to be a people to attach that volume unless that 51
condition createProdResources is true so unless we're selected prod and that 52
condition is true we will not be able to mount that volume. The resources section 53
is the only mandatory section of a cloudformation template and obviously it 54
declares the resources to be included so there we can see an example of a 55
resources section we've got a resource called my instance it's an ec2 instance 56
it has some properties there it has some user data that is going to be passed it 57
has an availability zone selected there and it has an image ID of an ami then 58
the outputs section can be used for a number of purposes first of all it can 59
be used as the inputs to another cloudformation template or stack it can also 60
be used to return information when I describe stack call as made using the 61
SDK or the command-line interface and it could also be used to display 62
information to the user on the management console in the example here 63
for an output section we can see that we've got an output called backup load 64
balancer DNS name and what it's doing it's returning a value from a function 65
get attributes for that backup load balancer and the attribute that it's 66
looking for is the DNS name so it's going to return the DNS name of your 67
load balancer the other one there is instance ID and it's going to return the 68
ec2 instance so when this stack is deployed the end-user is going to 69
receive the DNS name of that load balancer and they can connect to that 70
using their browser the AWS cloud formation stack set service is great if 71
you're a large organization that has multiple accounts and you want to 72
centrally manage the deployment of stacks across multiple AWS accounts the 73
administrator account will be the account where the stack was created and 74
that will be the account that will control the deployment of the stacks 75
and that allows a stack set to be created from the original stack and that 76
stack set can launch stack instances across multiple accounts and within 77
those accounts across multiple regions and the administrator accounts can 78
decide which accounts and which regions to launch that stack into 79
The Cloudformer tool will create a cloud formation template from your existing AWS 80
resources in your account you select the resources from your account using the 81
web interface of the AWS Cloudformer tool the cloud formation template that is 82
produced will be saved into an Amazon s3 bucket the Cloudformer tool is launched 83
using cloud formation and there is a stack created for Cloudformer so you 84
launch that cloud formation stack it will launch an ec2 instance and that ec2 85
instance will have the cloudformer application running on it and it 86
supports both JSON and YAML for its output templates the cloudformation 87
designer is a great productivity tool for using with cloudformation it allows 88
you to drag and drop resources onto a canvas and that will produce JSON or YAML 89
cloudformation templates for you and the files produced by cloudformation 90
designer can be saved locally you can use them with your own version control 91
system and when you import them back into cloudformation designer visually 92
they're exactly the same as when you left them so that brings us to the end 93
of the cloudformation lecture I hope you've learned a lot and I hope you've 94
enjoyed it and I look forward to seeing you in the next one