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
Functions
Properties
Configuration block(s) with DynamoDB Global Tables V2 (version 2019.11.21) replication configurations. See below.