1 00:00:06,900 --> 00:00:08,370 - Now let's review a demo 2 00:00:08,370 --> 00:00:11,670 of creating an Amazon DynamoDB table. 3 00:00:11,670 --> 00:00:13,220 From the console dashboard, 4 00:00:13,220 --> 00:00:16,810 we will go to DynamoDB 5 00:00:18,000 --> 00:00:21,310 And of course, we don't have any tables in this region yet. 6 00:00:21,310 --> 00:00:23,780 So before we create a table, 7 00:00:23,780 --> 00:00:26,190 I just wanna show you in the documentation 8 00:00:26,190 --> 00:00:27,532 Let me just switch tabs here. 9 00:00:27,532 --> 00:00:31,530 In the AWS documentation for Dynamo DB, 10 00:00:31,530 --> 00:00:34,746 you can find example tables and example data. 11 00:00:34,746 --> 00:00:39,746 So if you know, being new to DynamoDB, if you want to, 12 00:00:40,030 --> 00:00:42,230 you know learn more about programming 13 00:00:42,230 --> 00:00:45,270 against that particular data store, 14 00:00:45,270 --> 00:00:47,930 then you can look at the documentation 15 00:00:47,930 --> 00:00:50,163 for example tables and data, 16 00:00:51,270 --> 00:00:53,030 and example indexes 17 00:00:53,030 --> 00:00:54,890 and other kinds of things. 18 00:00:54,890 --> 00:00:59,190 So, we will go ahead and use Product Catalog 19 00:00:59,190 --> 00:01:00,850 for our table name. 20 00:01:00,850 --> 00:01:05,850 And we will use ID as a number for the primary key. 21 00:01:06,050 --> 00:01:08,370 All right. So I'll go ahead and copy that. 22 00:01:08,370 --> 00:01:11,300 And then we'll say create table. 23 00:01:11,300 --> 00:01:14,390 And then we'll use Product Catalog for the table name. 24 00:01:14,390 --> 00:01:19,300 And then DynamoDB being schema-less does not require us 25 00:01:19,300 --> 00:01:21,479 to specify the columns. 26 00:01:21,479 --> 00:01:25,390 Every item that we add to that table could have completely 27 00:01:25,390 --> 00:01:27,570 different attributes or columns. 28 00:01:27,570 --> 00:01:30,510 That probably wouldn't work very well for our application. 29 00:01:30,510 --> 00:01:34,060 But as far as DynamoDB is concerned, you know it's doesn't 30 00:01:34,060 --> 00:01:37,500 enforce any kind of schema except for the Primary Key. 31 00:01:37,500 --> 00:01:41,709 And so again, here in the documentation, the Primary Key 32 00:01:41,709 --> 00:01:45,530 is just a simple ID as a number. 33 00:01:45,530 --> 00:01:49,610 You could use other fields for the form table. 34 00:01:49,610 --> 00:01:51,670 It would be named as a 'String'. 35 00:01:51,670 --> 00:01:54,770 And then you can also make a Composite key, 36 00:01:54,770 --> 00:01:57,827 and the Composite key would be a combination of 37 00:01:57,827 --> 00:02:00,580 two different fields. 38 00:02:00,580 --> 00:02:05,030 And then of course, if you define these as being a part of 39 00:02:05,030 --> 00:02:08,487 the primary key, then that is really the only part of the 40 00:02:08,487 --> 00:02:13,180 schema that you might think of that is enforced. 41 00:02:13,180 --> 00:02:16,583 So every item would have to have an attribute 42 00:02:16,583 --> 00:02:18,850 with that particular name on it, 43 00:02:18,850 --> 00:02:21,060 and it would have to be unique. 44 00:02:21,060 --> 00:02:24,580 So, let's go back here to the table and say, 45 00:02:24,580 --> 00:02:27,820 'ID' as a Number 46 00:02:28,670 --> 00:02:31,810 and if we were to create one of those 47 00:02:31,810 --> 00:02:34,000 other tables that have a composite key, 48 00:02:34,000 --> 00:02:36,680 then the composite key, it would be a composite 49 00:02:36,680 --> 00:02:39,217 of the partition key plus a sort key. 50 00:02:39,217 --> 00:02:41,150 Uh, we won't worry about that for now. 51 00:02:41,150 --> 00:02:42,380 We will just keep it simple. 52 00:02:42,380 --> 00:02:44,764 And then of course down here, it says 53 00:02:44,764 --> 00:02:46,822 we could 'Use default settings'. 54 00:02:46,822 --> 00:02:49,240 And the default settings are: 55 00:02:49,240 --> 00:02:52,150 No secondary indexes, we'll talk more about those 56 00:02:53,100 --> 00:02:55,250 in a later lesson. 57 00:02:55,250 --> 00:02:57,440 And then we're gonna set Provisioned capacity 58 00:02:57,440 --> 00:02:59,940 to 5 reads and 5 writes. 59 00:02:59,940 --> 00:03:02,640 For a demo and if you were just creating 60 00:03:02,640 --> 00:03:05,170 like a Dev environment, then that's probably fine. 61 00:03:05,170 --> 00:03:08,250 You could probably even go as low as um 62 00:03:08,250 --> 00:03:11,020 If we wanted to have more control over this, 63 00:03:11,020 --> 00:03:13,950 then we could go to probably even 64 00:03:13,950 --> 00:03:17,330 looks like they're not gonna let us go lower than that. 65 00:03:17,330 --> 00:03:20,360 But even that is only gonna cost us about three dollars 66 00:03:20,360 --> 00:03:22,530 a month in capacity. 67 00:03:22,530 --> 00:03:25,520 We do have the option to turn on Auto-Scaling, 68 00:03:25,520 --> 00:03:28,870 so that DynamoDB can scale the capacity. 69 00:03:28,870 --> 00:03:31,910 Remember what we're paying for is a combination of 70 00:03:31,910 --> 00:03:34,490 Read capacity units and Write capacity units. 71 00:03:34,490 --> 00:03:37,450 And so you know, if what's actually happening 72 00:03:37,450 --> 00:03:40,810 is greater than or less than what we're paying for 73 00:03:40,810 --> 00:03:44,790 then we can use auto-scaling to help match 74 00:03:44,790 --> 00:03:48,410 you know, what is provision with what is actually happening. 75 00:03:48,410 --> 00:03:50,730 And that could, you know save us money. 76 00:03:50,730 --> 00:03:51,860 So I'm gonna turn those off. 77 00:03:51,860 --> 00:03:55,440 We actually don't really have a need for that in this demo. 78 00:03:55,440 --> 00:03:59,080 But in a production use case, you may very well want that. 79 00:03:59,080 --> 00:04:03,017 We also have the ability to encrypt our data at rest. 80 00:04:03,017 --> 00:04:08,017 All right. So here the default is to use 81 00:04:08,396 --> 00:04:11,640 an AWS owned Customer Master Key. 82 00:04:11,640 --> 00:04:13,840 Or you can use KMS. 83 00:04:13,840 --> 00:04:18,840 And this is a managed Customer Master Key using underneath 84 00:04:18,870 --> 00:04:20,130 the KMS service. 85 00:04:20,130 --> 00:04:22,590 And then of course, we can go create the table 86 00:04:23,646 --> 00:04:24,700 and it says 'Table is being created'. 87 00:04:24,700 --> 00:04:26,930 So let's go ahead. It usually doesn't take very long. 88 00:04:26,930 --> 00:04:28,430 So again, we don't have to necessarily 89 00:04:28,430 --> 00:04:30,208 refresh the whole screen. 90 00:04:30,208 --> 00:04:33,270 Most services give us this little refresh button. 91 00:04:33,270 --> 00:04:34,516 And there we go, just like that. 92 00:04:34,516 --> 00:04:35,694 Uh, pretty quick. 93 00:04:35,694 --> 00:04:39,766 And so, now we can review those table details. 94 00:04:39,766 --> 00:04:43,500 We have our table name, then our primary key is 95 00:04:43,500 --> 00:04:46,850 ID(Number), and then we're using KMS 96 00:04:46,850 --> 00:04:49,240 to help with encryption at rest. 97 00:04:49,240 --> 00:04:50,513 Uh, let's see here. 98 00:04:51,440 --> 00:04:55,710 And then we have provisioning 5 reads, 5 writes 99 00:04:55,710 --> 00:04:57,370 with auto-scaling disabled. 100 00:04:57,370 --> 00:05:00,010 And of course, this table is living in the Ohio region. 101 00:05:00,010 --> 00:05:02,070 And then again, I've mentioned this earlier, 102 00:05:02,070 --> 00:05:06,210 the Amazon Resource Name, the ARN, you may very well 103 00:05:06,210 --> 00:05:10,060 need to refer to this in your code. 104 00:05:10,060 --> 00:05:13,440 This is an important attribute of this table is the ARN. 105 00:05:13,440 --> 00:05:16,910 That's how we would identify in our code that 106 00:05:16,910 --> 00:05:19,260 that's the table we want to write to. 107 00:05:19,260 --> 00:05:20,300 Now in terms of storage, 108 00:05:20,300 --> 00:05:23,570 you'll notice that we did not need to specify storage. 109 00:05:23,570 --> 00:05:26,420 And that's because we don't provision storage 110 00:05:26,420 --> 00:05:28,050 within DynamoDB. 111 00:05:28,050 --> 00:05:30,892 Uh, storage just grows automatically and the storage plane 112 00:05:30,892 --> 00:05:34,853 just auto-scales, um as we add more data, 113 00:05:35,985 --> 00:05:39,890 DynamoDB just adds more resources to hold that data. 114 00:05:39,890 --> 00:05:43,231 And you can see here that we don't have any items 115 00:05:43,231 --> 00:05:45,640 in this table yet uh, right. 116 00:05:45,640 --> 00:05:47,210 So let's go ahead and do that real quick. 117 00:05:47,210 --> 00:05:50,821 I'm going to open up the console or open up my terminal 118 00:05:50,821 --> 00:05:55,821 and use this sample data that this developer guide gives us 119 00:05:57,350 --> 00:06:01,050 some sample data here. And I'm gonna open up the terminal 120 00:06:01,050 --> 00:06:02,710 and use the Command line interface 121 00:06:02,710 --> 00:06:07,710 to quickly load a number of records into that table. 122 00:06:08,260 --> 00:06:10,662 All right, so with my terminal in place, 123 00:06:10,662 --> 00:06:11,942 now we can... 124 00:06:11,942 --> 00:06:14,665 I'll show you that I have a folder over here 125 00:06:14,665 --> 00:06:19,489 called Sample Data. And in there, we have a few 126 00:06:19,489 --> 00:06:23,929 Json files that Amazon gives us. You can download that 127 00:06:23,929 --> 00:06:28,790 from the website, from the documentation. 128 00:06:28,790 --> 00:06:32,190 You can generally download .zip files of sample data. 129 00:06:32,190 --> 00:06:34,018 And they would show you exactly what to do 130 00:06:34,018 --> 00:06:37,650 in order to load that. And of course, you can use these 131 00:06:37,650 --> 00:06:41,680 kinds of things to automate the creation and population 132 00:06:41,680 --> 00:06:44,633 of tables. And you don't have to do it with the CLI. 133 00:06:44,633 --> 00:06:47,780 These are showing you how to do it the CLI tools. 134 00:06:47,780 --> 00:06:51,390 But you can do it with the CSDKs, and AWDS, you know 135 00:06:51,390 --> 00:06:56,230 provides SDKs for most of the popular languages. 136 00:06:56,230 --> 00:06:58,270 So, we'll go ahead and 137 00:06:58,270 --> 00:07:01,010 we'll go ahead and copy that, 138 00:07:01,010 --> 00:07:03,890 and we'll go back to our terminal and we'll go ahead 139 00:07:03,890 --> 00:07:07,217 and try this. So we're saying we're going to use the 140 00:07:07,217 --> 00:07:11,240 AWS CLI tools with using the DyanamDB service 141 00:07:11,240 --> 00:07:13,570 to write a number of items. 142 00:07:13,570 --> 00:07:17,326 We're doing a batch write, and we're saying that we're using 143 00:07:17,326 --> 00:07:19,630 the ProductCatalog Json here. 144 00:07:19,630 --> 00:07:20,760 So let's go ahead and try that. 145 00:07:20,760 --> 00:07:24,220 There we go. And know it's telling us the fact 146 00:07:24,220 --> 00:07:26,520 that we saw this as opposed to an error, 147 00:07:26,520 --> 00:07:28,950 means that that data should've loaded. 148 00:07:28,950 --> 00:07:30,660 And had we'd gotten an error, 149 00:07:30,660 --> 00:07:32,690 we would've of course seen that. 150 00:07:32,690 --> 00:07:35,550 So let's go back to our DynamoDB, 151 00:07:35,550 --> 00:07:38,610 and if we do a refresh here, there we go. 152 00:07:38,610 --> 00:07:40,800 We have some records in there. 153 00:07:40,800 --> 00:07:43,770 And we will continue to explore this. 154 00:07:43,770 --> 00:07:46,999 We will take a look at Scan and Query operations. 155 00:07:46,999 --> 00:07:51,999 The ability to query this table for particular items. 156 00:07:52,520 --> 00:07:55,263 We will look at that here in an upcoming demo.