welcome to programming and deployment using AWS cloud formation in the first 2
part of this lab we're going to look at developing a cloud formation template 3
now this is essentially a JSON file and we're going to use a JSON editor to 4
create that cloud formation template we're going to do this so that we can 5
visually see what is going on with the cloud formation JSON file and also that 6
we can create good quality JSON without any errors then we're going to actually 7
grab that cloud formation template and we're going to hand it over to our cloud 8
formation service which will create a cloud formation stack which will contain 9
resources that are defined in that template in the second part of this lab 10
we're going to look at a much quicker way of creating complex cloud formation 11
templates without having to use a JSON editor and what we're going to use is 12
cloud form and a cloud format is essentially an ec2 instance with some 13
software running on it that will look at our account and the resources within 14
that account and we can select from those resources and we can use those 15
resources that we've selected to define a cloud formation template and it will 16
automatically create that JSON file for us so this is very important when we're 17
got very complex architectures that are quite taking quite some time to develop 18
and we want to be able to keep track of those and any changes to that so very 19
good when combined with version control of those JSON documents as well so you 20
can actually see changes and the effects on those changes and and and roll back 21
to previous versions if you have issues then we're going to look at using that 22
cloud formation template that was developed from cloud format and we're 23
going to use that again to create those resources that we've defined using cloud 24
former so we're just going to jump into our 25
JSON is there at JSON editor oh sorry JSON editor online dot org and we just 26
pass in some curly brackets here on the side here and then just pass it across 27
to have an empty object so the first thing we're going to put inside our 28
object will be a string and that's going to be the version of our template so 29
that's that's not essential but it is recommended because you should really 30
define what version of the the cloud formation template that you're actually 31
writing for so in the future if there are changes you're cloud formation 32
template will still work the next thing we're going to read in it will be a 33
description so we'll just append and we put in a string again a description and 34
the next one we're going to put in it will be what we're just still 35
description probably first the next one we're going to put in there will be an 36
object and that's going to be a parameters object so the parameters what 37
we are going to get from the user at launch time so there's going to be 38
parameters that we're going to set up our resources with so it can be for 39
example if it's a dynamo DB instance that we're launching then we'll be 40
looking at read and write capacity of that that dynamo DB instance so we just 41
put that in there now and the next thing we would like to add will be another 42
object so I just made a mistake there so I'll just get rid of that so don't make 43
a mistake just go back and you can remove and so I've actually appended it 44
to the object and not the actual of a pendant or a meters instead of the main 45
objects so I just hand that there now and put in an object the next one is 46
going to be resources now the resources section is the only section of the 47
template that is essential so we can do with our parameters description template 48
format version outputs etc but the resources we have to have a resources 49
section the reason being if there's no resources we're not going 50
to be creating anything so obviously you need to have a resources section so just 51
pop that in now and the next thing we're going to add in there will be outputs so 52
it's going to pend another object in there and we're going to call that 53
outputs okay so we just pass that across we'll have a look at that so there we go 54
a template version we've got a street description the parameters object 55
resources object and the outputs object so in the output section so when we've 56
when we're launching our stack these outputs will be output it to the users 57
to give them the information on board on what's going on so we have parameters 58
which will be taking inputs from the user and outputs which you'll be 59
outputting information to the user 60
okay so I've just finished populating all of this so thanks to the magic of 61
pre-recorded video that's all been done I decided not to go through and bore you 62
to death and how to use the JSON editor the notes there are very very specific 63
on how to do all that so just go through and you need to get stuck you can always 64
cut and paste from the gist file at at nd so let's have a look at this so we've 65
got our parameters section so again this is going to be what we pass to set up 66
our instance when it's created so there's a way our stack so what we what 67
we've going to have here is that we want to know the read capacity units so when 68
the user launches his stack he will be our he or she will be asked for - for 69
the read capacity and write capacity units and these are the same just put the 70
values in here are the same other looks of things but on launch you'll be are 71
valid by putting different values for each one so what have we got here so 72
we've got a description obviously and then that's height what we're asking for 73
is a number that's quite obvious so default so what's going to happen is 74
that when it when the screen first comes up for read capacity units it will have 75
already put in there the number of one and so the minimum number we can put in 76
there is of one and then we've got a maximum number 77
that we can put in there which is which you've got there ten thousand and the 78
constraint we've got a description for into saying it must be between one and a 79
thousand so that's how we how we do parameters and we're going to get our 80
read capacity unit so we can actually refer to those further on in our in our 81
resources section so let's have a look at that so many resources again the 82
essential component of a cloud formation JSON file that you must have so we've 83
got the name of the table so the resource is called table of products and 84
so that's another object inside of this object and then we've got a text which 85
is type and the type is a dynamodb table so that's quite self-explanatory table 86
of products which is a dynamodb table and then we've got the properties of 87
this table so we've got attribute definitions so we create attribute 88
definitions which we can then refer to in other areas of our our cloud 89
formation template so let's have a look at that so we've got three attribute 90
definitions so the first one is going to be the ID which is a number and we're 91
going to obviously refer that that's going to be out our primary key for this 92
database and so we will be referring to ID later on and then we've got product 93
category which is a string and that again is going to be referred to because 94
it's part of the it'll be the hash for the global secondary index and then 95
we've got the price which will be referred to later on which is our range 96
for the global secondary index so I'll just close that there now and we're 97
going to schema so we've got an object which is actually an array so we can 98
multiple objects inside of this here and an attribute of definitions also is an 99
array so you have multiple objects so you can have many of those attribute 100
definitions inside this array so key schema 101
and here is it here we have our primary key which is ID and hash so we've 102
referred to this attribute ID which is in here so we've got the attribute name 103
ID and our attribute definitions and that's how we refer to that there and 104
then what it is it's a key type hash and here is where we can refer to our recap 105
asset units so we look at there and we're referencing read capacity units 106
which was in our parameters section so we're looking here really capacity units 107
which is what we're going to get at launch time from our user and the same 108
for our write capacity units so we're referencing the right capacity units 109
that we get from our parameters section then we've got a global secondary 110
indexes and now this is an array also so we can have multiples in here of if it 111
would accept that and so then we've got our global second unix which is going to 112
have an index name and it will also have a key schemer and which will have two 113
objects in it so the first one being our hash which is product category which we 114
have referred to again in our attribute definitions here product category and 115
we've also got another attribute price which we are referring to as our range 116
key there and then projection we're going to be just projecting all we're 117
not going to be limiting the projection of anything there and our provision 118
through port again we're referring to our recap asset e units in our 119
parameters section so what we're going to get from the user at launch of this 120
stack so there we have it so the properties we're going to have attribute 121
definitions the key schemas were primary key a provision throughput and the 122
global secondary occurs which will have its own set of schema and provisions 123
throughput as well and then the output so just like we have parameters that are 124
going to be getting inputs we have outputs that will be outputting 125
information to the user as well so we're going to be outputting 126
table name which will be the value or to have a description and the value for 127
table name that we're outputting will be table of products which is referencing 128
table of products and so we're going to revolt resources table of products here 129
so we'll just jump now into cloud or formation and we'll run our template so 130
we are now in the cloud formation console so we can see we've got a number 131
of options here to create a stack or created template from our existing 132
resources so we can actually launch cloud former or we can create a new 133
stack so later on we will look at using cloud format to create a snapshot of all 134
of our resources and put that into a template that we can we can use later on 135
so we're just going to go in to create a new stack and we'll give you a stack a 136
name and then we're going to get our template so up so select a sample a 137
template so we we need to upload a template to Amazon s3 and we choose our 138
file that we that we saved our JSON folder we saved 139
okay so now we can click on next 140
okay so now we're in the parameters section so again in our template we had 141
a parameter section so we're being asked now to specify the parameters for Rika 142
passer units and write capacity units in here we've got our default of 1 and we 143
can change it if we won't believe that it's 1 we don't want to spend too much 144
money on a lab here and we click Next okay so we need some additional tags in 145
there we won't bother with this we can add some notifications there so we won't 146
do any notifications there either so just click on next so we've got a review 147
here so basically we've given it a name I've given mine called backspace - lead 148
we've got a URL for that for that template that we've just uploaded we've 149
got a description so that description came from our our template and then 150
we've got our read capacity units and write capacity units and again that came 151
from our or where they came from the default unit in our template and we've 152
got no other options there so that's fine and roll back on failure is 153
selected as year so that's that's quite important so if something does fail then 154
we don't end up with a whole heap of resources that are that we need to go 155
through and delete afterwards ok so we just click on create now ok we can see 156
it's in progress and it will eventually change from creating progress to to 157
complete so we just click on refreshing there so what we can see is we can see 158
the events that are going on here so so the user has initiated the cloud 159
formation stack we're currently creating the dynamodb table and that will have a 160
physical ID here we've got for that dynamodb table and it's going to be 161
creating the resources there for it so just fast-forwarding there the stack has 162
been completed that create complete so you can see here create we have created 163
table of products and everything's fishiest so we should be now able to go 164
into into dynamo dB and have a look at that so we'll just do 165
that now go to services and DynamoDB let's have a look and we'll be looking 166
for a dynamo DB instance called back space - lab table of products and some 167
other guff on the end of it ok so there it is there back space - lab - table of 168
products and it has the hash key of ID that we specified their dough range and 169
the sum of read-through put in some of right throughput which will be the sum 170
of the indexes and the and the the key so we look in here we've got here 171
provisioned a tree capacity one which came from our template and the provision 172
of right capacity which came from our template also our table name table of 173
products here, and we've got ID number with the primary key and we've also got here 174
an arn let's go into indexes ok so we can see here alright so what have we got 175
here we've got no local secondary indexes it doesn't have any we didn't 176
define any but it's got a global secondary index so there's a name of it 177
that came from that template we've got a product category for the hash again from 178
the template and a range again from the template we've projected all all 179
attributes that came from the template as well the recap asset e and write 180
capacity units also came from the template so we've successfully created 181
everything that was in that all of the resources that were in in that template 182
and and set it up with the appropriate parameters that we that we were looking 183
for so in the in the next part of this label look at using cloud formation to 184
take snapshots of what we've created