Table Args
Provides a DynamoDB table resource.
Note: It is recommended to use
ignoreChanges
forread_capacity
and/orwrite_capacity
if there'sautoscaling policy
attached to the table. Note: When using aws.dynamodb.TableReplica with this resource, uselifecycle
ignore_changes
forreplica
, e.g.,lifecycle { ignore_changes = [replica] }
.
DynamoDB Table attributes
Only define attributes on the table object that are going to be used as:
Table hash key or range key
LSI or GSI hash key or range key The DynamoDB API expects attribute structure (name and type) to be passed along when creating or updating GSI/LSIs or creating the initial table. In these cases it expects the Hash / Range keys to be provided. Because these get re-used in numerous places (i.e the table's range key could be a part of one or more GSIs), they are stored on the table object to prevent duplication and increase consistency. If you add attributes here that are not used in these scenarios it can cause an infinite loop in planning.
Example Usage
Basic Example
The following dynamodb table description models the table and GSI shown in the AWS SDK example documentation
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.dynamodb.Table;
import com.pulumi.aws.dynamodb.TableArgs;
import com.pulumi.aws.dynamodb.inputs.TableAttributeArgs;
import com.pulumi.aws.dynamodb.inputs.TableGlobalSecondaryIndexArgs;
import com.pulumi.aws.dynamodb.inputs.TableTtlArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var basic_dynamodb_table = new Table("basic-dynamodb-table", TableArgs.builder()
.attributes(
TableAttributeArgs.builder()
.name("UserId")
.type("S")
.build(),
TableAttributeArgs.builder()
.name("GameTitle")
.type("S")
.build(),
TableAttributeArgs.builder()
.name("TopScore")
.type("N")
.build())
.billingMode("PROVISIONED")
.globalSecondaryIndexes(TableGlobalSecondaryIndexArgs.builder()
.hashKey("GameTitle")
.name("GameTitleIndex")
.nonKeyAttributes("UserId")
.projectionType("INCLUDE")
.rangeKey("TopScore")
.readCapacity(10)
.writeCapacity(10)
.build())
.hashKey("UserId")
.rangeKey("GameTitle")
.readCapacity(20)
.tags(Map.ofEntries(
Map.entry("Environment", "production"),
Map.entry("Name", "dynamodb-table-1")
))
.ttl(TableTtlArgs.builder()
.attributeName("TimeToExist")
.enabled(false)
.build())
.writeCapacity(20)
.build());
}
}
Global Tables
This resource implements support for DynamoDB Global Tables V2 (version 2019.11.21) via replica
configuration blocks. For working with DynamoDB Global Tables V1 (version 2017.11.29), see the aws.dynamodb.GlobalTable
resource.
Note: aws.dynamodb.TableReplica is an alternate way of configuring Global Tables. Do not use
replica
configuration blocks ofaws.dynamodb.Table
together with aws_dynamodb_table_replica.
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.dynamodb.Table;
import com.pulumi.aws.dynamodb.TableArgs;
import com.pulumi.aws.dynamodb.inputs.TableAttributeArgs;
import com.pulumi.aws.dynamodb.inputs.TableReplicaArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var example = new Table("example", TableArgs.builder()
.attributes(TableAttributeArgs.builder()
.name("TestTableHashKey")
.type("S")
.build())
.billingMode("PAY_PER_REQUEST")
.hashKey("TestTableHashKey")
.replicas(
TableReplicaArgs.builder()
.regionName("us-east-2")
.build(),
TableReplicaArgs.builder()
.regionName("us-west-2")
.build())
.streamEnabled(true)
.streamViewType("NEW_AND_OLD_IMAGES")
.build());
}
}
Import
DynamoDB tables can be imported using the name
, e.g.,
$ pulumi import aws:dynamodb/table:Table basic-dynamodb-table GameScores
Constructors
Properties
Set of nested attribute definitions. Only required for hash_key
and range_key
attributes. See below.
Controls how you are charged for read and write throughput and how you manage capacity. The valid values are PROVISIONED
and PAY_PER_REQUEST
. Defaults to PROVISIONED
.
Enables deletion protection for table. Defaults to false
.
Describe a GSI for the table; subject to the normal limits on the number of GSIs, projected attributes, etc. See below.
Describe an LSI on the table; these can only be allocated at creation so you cannot change this definition after you have created the resource. See below.
Enable point-in-time recovery options. See below.
Number of read units for this table. If the billing_mode
is PROVISIONED
, this field is required.
Configuration block(s) with DynamoDB Global Tables V2 (version 2019.11.21) replication configurations. See below.
Time of the point-in-time recovery point to restore.
Name of the table to restore. Must match the name of an existing table.
If set, restores table to the most recent point-in-time recovery point.
Encryption at rest options. AWS DynamoDB tables are automatically encrypted at rest with an AWS-owned Customer Master Key if this argument isn't specified. See below.
Whether Streams are enabled.
When an item in the table is modified, StreamViewType determines what information is written to the table's stream. Valid values are KEYS_ONLY
, NEW_IMAGE
, OLD_IMAGE
, NEW_AND_OLD_IMAGES
.
Storage class of the table. Valid values are STANDARD
and STANDARD_INFREQUENT_ACCESS
. Default value is STANDARD
.
Configuration block for TTL. See below.
Number of write units for this table. If the billing_mode
is PROVISIONED
, this field is required.