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