Provide a Pulumi schema example with a primary key.TypeScript
Sure, using the
aws.dynamodb.Tableresource, you can create a table that contains a primary key by defining it under the
Here is the code in TypeScript:
In this example, we're using AWS DynamoDB which is a key-value and document database that delivers single-digit millisecond performance at any scale. A primary key in DynamoDB is a unique attribute that serves two main purposes:
- It uniquely identifies each item in a table. No two items share the same primary key.
- It provides the basis for the table's hash indexes.
The table's primary key is defined while creating the table and cannot be changed. Each primary key attribute must be a scalar (meaning that it can hold only one value). After you've designed the table's schema by specifying its primary key and any secondary indexes, DynamoDB takes care of the rest.
In our Pulumi program, the primary key is defined by the
hashKeyattribute and references one of the attribute names we specify under the
attributesproperty "Id" in this case. Also note, the types for the attributes are defined there too, 'N' is for number and 'S' for string.
This table will end up with a primary key named "Id" with the type Number.
For more details, you can refer to
aws.dynamodb.Tablein the Pulumi Registry.