AWS DynamoDB Table

This page shows how to write Terraform and CloudFormation for DynamoDB Table and write them securely.

aws_dynamodb_table (Terraform)

The Table in DynamoDB can be configured in Terraform with the resource name aws_dynamodb_table. The following sections describe 5 examples of how to use the resource and its parameters.

Example Usage from GitHub

github-iconRPISDD/DeployScripts
resource "aws_dynamodb_table" "class-hours-table" {
  name = "classHours"
  read_capacity = 2
  write_capacity = 2
  hash_key = "CRN"
  attribute {
github-iconDaveButland/sans-terraform
resource "aws_dynamodb_table" "sans_website_folders" {
  name           = "sans-folders"
  billing_mode   = "PROVISIONED"
  read_capacity  = 1
  write_capacity = 1
  hash_key       = "userId"
github-iconpalerique/dynamodb-studies
resource "aws_dynamodb_table" "Music" {
  name           = "Music"
  read_capacity  = 5
  write_capacity = 5
  hash_key       = "Artist"
  range_key      = "SongTitle"
github-iconpalerique/dynamodb-studies
resource "aws_dynamodb_table" "Music" {
  name           = "Music"
  read_capacity  = 5
  write_capacity = 5
  hash_key       = "Artist"
  range_key      = "SongTitle"
github-iconpalerique/dynamodb-studies
resource "aws_dynamodb_table" "dragon_bonus_attack" {
  name           = "dragon_bonus_attack"
  read_capacity  = 0
  write_capacity = 0
  hash_key       = "breath_attack"
  range_key      = "range"

Parameters

Explanation in Terraform Registry

Provides a DynamoDB table resource

Note: It is recommended to use lifecycle ignore_changes for read_capacity and/or write_capacity if there's autoscaling policy attached to the table.

AWS::DynamoDB::Table (CloudFormation)

The Table in DynamoDB can be configured in CloudFormation with the resource name AWS::DynamoDB::Table. The following sections describe how to use the resource and its parameters.

Parameters

Explanation in CloudFormation Registry

The AWS::DynamoDB::Table resource creates a DynamoDB table. For more information, see CreateTable in the Amazon DynamoDB API Reference.

You should be aware of the following behaviors when working with DynamoDB tables:+ AWS CloudFormation typically creates DynamoDB tables in parallel. However, if your template includes multiple DynamoDB tables with indexes, you must declare dependencies so that the tables are created sequentially. Amazon DynamoDB limits the number of tables with secondary indexes that are in the creating state. If you create multiple tables with indexes at the same time, DynamoDB returns an error and the stack operation fails. For an example, see DynamoDB Table with a DependsOn Attribute.

Frequently asked questions

What is AWS DynamoDB Table?

AWS DynamoDB Table is a resource for DynamoDB of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.

Where can I find the example code for the AWS DynamoDB Table?

For Terraform, the RPISDD/DeployScripts, DaveButland/sans-terraform and palerique/dynamodb-studies source code examples are useful. See the Terraform Example section for further details.