WEBVTT

00:00.420 --> 00:01.520
In this lecture,

00:01.520 --> 00:06.460
we will see how to create and manage
DynamoDB tables using terraform.

00:07.900 --> 00:10.700
To create DynamoDB tables using terraform,

00:10.700 --> 00:15.700
we can make use of the AWS DynamoDB table
resource type.

00:16.380 --> 00:18.520
Using the same example as before,

00:18.520 --> 00:22.480
let's create a table that
will store information about cars.

00:23.340 --> 00:28.160
This resource block expects a name,
which is the name of the DynamoDB table

00:28.160 --> 00:31.880
and the hash key,
which denotes the primary key for the table.

00:32.920 --> 00:38.140
Besides these two arguments, we must also
make use of the argument called attribute,

00:38.140 --> 00:40.580
which is used to store attributes of the table

00:40.580 --> 00:43.800
such as the manufacturer, model name, et cetera.

00:44.940 --> 00:46.440
If you look at the syntax,

00:46.440 --> 00:51.200
you will note that the attribute is defined
as another block within the resource block.

00:51.980 --> 00:55.900
You can add as many attributes as needed
within the attribute block,

00:55.900 --> 00:58.340
but the primary key is mandatory.

00:59.660 --> 01:05.400
In our example, this is the vehicle
identification number or VIN of type string,

01:05.400 --> 01:08.660
which is denoted by the upper case letter S.

01:09.840 --> 01:13.780
Also note that we have added
another argument called billing mode.

01:13.880 --> 01:18.360
This argument controls how we are charged
for read and writes to this table

01:18.360 --> 01:20.360
and how to manage capacity.

01:21.020 --> 01:24.740
As we saw in the demo,
this is set to provisioned by default.

01:24.740 --> 01:28.860
In which case we have to declare
the read and write capacity units.

01:29.260 --> 01:34.820
In this example, we have set it to the mode
PAY-PER-REQUEST or the on-demand mode.

01:35.680 --> 01:39.480
We are now ready to run our plan
and then apply on this configuration

01:39.480 --> 01:42.260
to create the DynamoDB table called cars.

01:43.240 --> 01:47.120
The next step is to add items to the table
that we have just created.

01:48.040 --> 01:50.180
To insert new items into the table,

01:50.300 --> 01:55.840
we can make use of another resource type
called AWS DynamoDB table item.

01:56.520 --> 01:59.380
This resource expects
three required arguments,

01:59.380 --> 02:01.380
the table name and the hash key,

02:01.560 --> 02:04.520
both of which can be specified
using reference expressions

02:04.520 --> 02:06.700
from the DynamoDB table resource.

02:07.520 --> 02:09.460
The next argument is the item.

02:09.900 --> 02:15.120
For item, we can make use of the heredoc syntax
using EOF as the delimiter,

02:15.380 --> 02:20.640
and then we move one of the example documents
under the item argument like this.

02:21.940 --> 02:27.120
However, the item argument expects
the value to be in a JSON representation

02:27.180 --> 02:30.040
with the type and value split like this.

02:30.420 --> 02:32.880
S for string and N for number.

02:33.500 --> 02:37.920
Only the hash key attribute,
which is the VIN in this case, is required.

02:38.140 --> 02:39.780
The rest are optional.

02:40.620 --> 02:45.820
Running the terraform apply now will insert
the item into the DynamoDB table called cars.

02:46.440 --> 02:50.540
Before we move on, please note that
this method is not meant to be used

02:50.540 --> 02:53.300
for managing large amounts
of data in the table.

02:53.960 --> 02:58.640
This is a simplified example of
creating a table and adding items to it.

02:59.700 --> 03:01.960
Now, let's head over to the hands-on labs

03:01.960 --> 03:05.460
and practice working with
DynamoDB tables in terraform.

