1. Answers
  2. Configuring an AWS DynamoDB Table

How do I configure an AWS DynamoDB table?

Setting up an AWS DynamoDB table involves defining the necessary configurations such as the table name, attributes, key schema, and provisioned throughput. Below is an example that demonstrates how to configure an AWS DynamoDB table.

In this example, we’ll create a DynamoDB table with a simple primary key structure (a partition key). We will also specify the provisioned throughput settings for read and write capacity.

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

// Create a DynamoDB table
const example = new aws.dynamodb.Table("example", {
    name: "example-table",
    billingMode: "PROVISIONED",
    attributes: [{
        name: "id",
        type: "S",
    }],
    hashKey: "id",
    readCapacity: 5,
    writeCapacity: 5,
    serverSideEncryption: {
        enabled: true,
    },
    streamEnabled: true,
    streamViewType: "NEW_AND_OLD_IMAGES",
});
export const dynamodbTableName = example.name;
export const dynamodbTableArn = example.arn;

We start by specifying the AWS provider and setting the desired region. After that, we define the DynamoDB table resource. The name attribute specifies the table name, and billing_mode is set to “PROVISIONED” indicating that we will specify the read and write capacity units.

The attribute block defines the attributes used in the table’s schema. Here, we define a single attribute id of type string (S). The hash_key is set to “id”, indicating that id will be used as the partition key.

In the provisioned throughput settings, we set read_capacity and write_capacity to 5. Server-side encryption is enabled by default with AWS managed keys by setting enabled to true in the server_side_encryption block.

Finally, the stream_enabled and stream_view_type properties are used to enable DynamoDB streams on the table, capturing both new and old images of the items as they are modified.

The outputs section provides the created table’s name and Amazon Resource Name (ARN) for reference.

In summary, this code configures a basic DynamoDB table on AWS, establishing key schema attributes, sets up provisioned throughput, and enables server-side encryption.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up