A Pulumi provider SDK for creating and managing Amazon Web Services (AWS) cloud resources in Go, providing strongly-typed resource classes and data sources for all major AWS services.
The dynamodb package provides resources for managing Amazon DynamoDB tables, global tables, table items, replicas, indexes, streams, and related features.
import "github.com/pulumi/pulumi-aws/sdk/v7/go/aws/dynamodb"// Resources
NewContributorInsights(ctx, name, args, opts) (*ContributorInsights, error)
NewGlobalSecondaryIndex(ctx, name, args, opts) (*GlobalSecondaryIndex, error)
NewGlobalTable(ctx, name, args, opts) (*GlobalTable, error)
NewKinesisStreamingDestination(ctx, name, args, opts) (*KinesisStreamingDestination, error)
NewResourcePolicy(ctx, name, args, opts) (*ResourcePolicy, error)
NewTable(ctx, name, args, opts) (*Table, error)
NewTableExport(ctx, name, args, opts) (*TableExport, error)
NewTableItem(ctx, name, args, opts) (*TableItem, error)
NewTableReplica(ctx, name, args, opts) (*TableReplica, error)
NewTag(ctx, name, args, opts) (*Tag, error)
// Data Sources / Lookup Functions
GetContributorInsights(ctx, name, id, state, opts) (*ContributorInsights, error)
GetGlobalSecondaryIndex(ctx, name, id, state, opts) (*GlobalSecondaryIndex, error)
GetGlobalTable(ctx, name, id, state, opts) (*GlobalTable, error)
GetKinesisStreamingDestination(ctx, name, id, state, opts) (*KinesisStreamingDestination, error)
GetResourcePolicy(ctx, name, id, state, opts) (*ResourcePolicy, error)
GetTable(ctx, name, id, state, opts) (*Table, error)
GetTableExport(ctx, name, id, state, opts) (*TableExport, error)
GetTableItem(ctx, name, id, state, opts) (*TableItem, error)
GetTableReplica(ctx, name, id, state, opts) (*TableReplica, error)
GetTables(ctx, args, opts) (*GetTablesResult, error)
GetTablesOutput(ctx, args, opts) GetTablesResultOutput
GetTag(ctx, name, id, state, opts) (*Tag, error)
LookupTable(ctx, args, opts) (*LookupTableResult, error)TableProvides a DynamoDB table resource. This is the primary resource for creating and managing DynamoDB tables, including support for Global Tables V2 (version 2019.11.21) via the Replicas block.
Note: Use
ignoreChangesonreadCapacityand/orwriteCapacityif an autoscaling policy is attached. UseignoreChangesonreplicawhen managing replicas viadynamodb.TableReplica.
func NewTable(
ctx *pulumi.Context,
name string,
args *dynamodb.TableArgs,
opts ...pulumi.ResourceOption,
) (*dynamodb.Table, error)TableArgs Fieldstype TableArgs struct {
// Attribute definitions. Only required for hashKey and rangeKey attributes,
// plus any attributes used as LSI/GSI keys.
// Each attribute has a Name (string) and Type ("S", "N", or "B").
Attributes TableAttributeArrayInput
// Billing mode. Values: "PROVISIONED" (default), "PAY_PER_REQUEST".
BillingMode pulumi.StringPtrInput
// Enable deletion protection. Default: false.
DeletionProtectionEnabled pulumi.BoolPtrInput
// Global Secondary Index definitions. See GSI limits in AWS docs.
GlobalSecondaryIndexes TableGlobalSecondaryIndexArrayInput
// Witness region for Multi-Region Strong Consistency.
// Must be used with a single replica whose ConsistencyMode is "STRONG".
GlobalTableWitness TableGlobalTableWitnessPtrInput
// Hash (partition) key attribute name. Must also be defined in Attributes.
HashKey pulumi.StringPtrInput
// Import data from Amazon S3 when creating the table.
ImportTable TableImportTablePtrInput
// Local Secondary Index definitions. Can only be set at creation time; immutable.
LocalSecondaryIndexes TableLocalSecondaryIndexArrayInput
// Table name. Unique within the region. Auto-generated if omitted.
Name pulumi.StringPtrInput
// Maximum on-demand throughput for PAY_PER_REQUEST tables.
OnDemandThroughput TableOnDemandThroughputPtrInput
// Point-in-time recovery configuration.
PointInTimeRecovery TablePointInTimeRecoveryPtrInput
// Range (sort) key attribute name. Must also be defined in Attributes.
RangeKey pulumi.StringPtrInput
// Read capacity units. Required when BillingMode is "PROVISIONED".
ReadCapacity pulumi.IntPtrInput
// AWS region override.
Region pulumi.StringPtrInput
// Global Tables V2 replica configuration blocks.
// Use ignoreChanges on this field when also managing replicas via TableReplica.
Replicas TableReplicaTypeArrayInput
// Restore point-in-time timestamp (ISO 8601). Used with RestoreSourceName.
RestoreDateTime pulumi.StringPtrInput
// Name of the table to restore from. Required for PITR restores.
RestoreSourceName pulumi.StringPtrInput
// ARN of the source table for cross-region restores.
RestoreSourceTableArn pulumi.StringPtrInput
// Restore to the most recent PITR point. Default: false.
RestoreToLatestTime pulumi.BoolPtrInput
// Server-side encryption configuration block.
// AWS-owned CMK used by default; set Enabled=true to use a customer-managed key.
ServerSideEncryption TableServerSideEncryptionPtrInput
// Enable DynamoDB Streams. Default: false.
StreamEnabled pulumi.BoolPtrInput
// Stream view type. Values: "KEYS_ONLY", "NEW_IMAGE", "OLD_IMAGE", "NEW_AND_OLD_IMAGES".
// Required when StreamEnabled is true.
StreamViewType pulumi.StringPtrInput
// Table class. Values: "STANDARD" (default), "STANDARD_INFREQUENT_ACCESS".
TableClass pulumi.StringPtrInput
// Resource tags.
Tags pulumi.StringMapInput
// Time-to-live (TTL) configuration block.
Ttl TableTtlPtrInput
// Warm throughput configuration.
WarmThroughput TableWarmThroughputPtrInput
// Write capacity units. Required when BillingMode is "PROVISIONED".
WriteCapacity pulumi.IntPtrInput
}Table Output Attributes| Field | Type | Description |
|---|---|---|
Arn | pulumi.StringOutput | ARN of the table |
Name | pulumi.StringOutput | Table name |
HashKey | pulumi.StringOutput | Hash (partition) key attribute name |
RangeKey | pulumi.StringPtrOutput | Range (sort) key attribute name |
BillingMode | pulumi.StringPtrOutput | Billing mode in use |
ReadCapacity | pulumi.IntOutput | Current read capacity units |
WriteCapacity | pulumi.IntOutput | Current write capacity units |
StreamArn | pulumi.StringOutput | Stream ARN (when StreamEnabled is true) |
StreamLabel | pulumi.StringOutput | Stream timestamp label |
StreamViewType | pulumi.StringOutput | Stream view type |
TableClass | pulumi.StringPtrOutput | Storage class |
| Code | Type |
|---|---|
S | String |
N | Number |
B | Binary |
import (
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/dynamodb"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
table, err := dynamodb.NewTable(ctx, "users", &dynamodb.TableArgs{
Name: pulumi.String("users"),
BillingMode: pulumi.String("PROVISIONED"),
ReadCapacity: pulumi.Int(5),
WriteCapacity: pulumi.Int(5),
HashKey: pulumi.String("userId"),
RangeKey: pulumi.String("createdAt"),
Attributes: dynamodb.TableAttributeArray{
&dynamodb.TableAttributeArgs{
Name: pulumi.String("userId"),
Type: pulumi.String("S"),
},
&dynamodb.TableAttributeArgs{
Name: pulumi.String("createdAt"),
Type: pulumi.String("S"),
},
&dynamodb.TableAttributeArgs{
Name: pulumi.String("email"),
Type: pulumi.String("S"),
},
},
GlobalSecondaryIndexes: dynamodb.TableGlobalSecondaryIndexArray{
&dynamodb.TableGlobalSecondaryIndexArgs{
Name: pulumi.String("email-index"),
HashKey: pulumi.String("email"),
ProjectionType: pulumi.String("ALL"),
ReadCapacity: pulumi.Int(5),
WriteCapacity: pulumi.Int(5),
},
},
Ttl: &dynamodb.TableTtlArgs{
AttributeName: pulumi.String("expiresAt"),
Enabled: pulumi.Bool(true),
},
Tags: pulumi.StringMap{
"Environment": pulumi.String("production"),
},
})
if err != nil {
return err
}
ctx.Export("tableArn", table.Arn)
return nil
})
}_, err := dynamodb.NewTable(ctx, "events", &dynamodb.TableArgs{
Name: pulumi.String("events"),
BillingMode: pulumi.String("PAY_PER_REQUEST"),
HashKey: pulumi.String("eventId"),
StreamEnabled: pulumi.Bool(true),
StreamViewType: pulumi.String("NEW_AND_OLD_IMAGES"),
Attributes: dynamodb.TableAttributeArray{
&dynamodb.TableAttributeArgs{
Name: pulumi.String("eventId"),
Type: pulumi.String("S"),
},
},
ServerSideEncryption: &dynamodb.TableServerSideEncryptionArgs{
Enabled: pulumi.Bool(true),
},
PointInTimeRecovery: &dynamodb.TablePointInTimeRecoveryArgs{
Enabled: pulumi.Bool(true),
},
})_, err := dynamodb.NewTable(ctx, "global", &dynamodb.TableArgs{
Name: pulumi.String("global-table"),
BillingMode: pulumi.String("PAY_PER_REQUEST"),
HashKey: pulumi.String("id"),
StreamEnabled: pulumi.Bool(true),
StreamViewType: pulumi.String("NEW_AND_OLD_IMAGES"),
Attributes: dynamodb.TableAttributeArray{
&dynamodb.TableAttributeArgs{
Name: pulumi.String("id"),
Type: pulumi.String("S"),
},
},
Replicas: dynamodb.TableReplicaTypeArray{
&dynamodb.TableReplicaTypeArgs{
RegionName: pulumi.String("us-east-1"),
},
&dynamodb.TableReplicaTypeArgs{
RegionName: pulumi.String("eu-west-1"),
},
},
})GlobalTableManages DynamoDB Global Tables V1 (version 2017.11.29). These are layered on top of existing DynamoDB tables.
Note: For Global Tables V2 (version 2019.11.21), use the
Replicasblock on thedynamodb.Tableresource instead.
func NewGlobalTable(
ctx *pulumi.Context,
name string,
args *dynamodb.GlobalTableArgs,
opts ...pulumi.ResourceOption,
) (*dynamodb.GlobalTable, error)GlobalTableArgs Fieldstype GlobalTableArgs struct {
// Name of the global table. Must match DynamoDB table names in all replica regions. Required.
Name pulumi.StringPtrInput
// Replica definitions. At least one replica required.
// Each replica block has a RegionName field.
Replicas GlobalTableReplicaArrayInput
// AWS region override.
Region pulumi.StringPtrInput
}GlobalTable Output Attributes| Field | Type | Description |
|---|---|---|
Arn | pulumi.StringOutput | ARN of the DynamoDB Global Table |
Name | pulumi.StringOutput | Global table name |
// Create the underlying tables in each region first
usTable, _ := dynamodb.NewTable(ctx, "us-east-1", &dynamodb.TableArgs{
Name: pulumi.String("myTable"),
HashKey: pulumi.String("id"),
StreamEnabled: pulumi.Bool(true),
StreamViewType: pulumi.String("NEW_AND_OLD_IMAGES"),
ReadCapacity: pulumi.Int(1),
WriteCapacity: pulumi.Int(1),
Attributes: dynamodb.TableAttributeArray{
&dynamodb.TableAttributeArgs{Name: pulumi.String("id"), Type: pulumi.String("S")},
},
})
euTable, _ := dynamodb.NewTable(ctx, "eu-west-1", &dynamodb.TableArgs{
Name: pulumi.String("myTable"),
HashKey: pulumi.String("id"),
StreamEnabled: pulumi.Bool(true),
StreamViewType: pulumi.String("NEW_AND_OLD_IMAGES"),
ReadCapacity: pulumi.Int(1),
WriteCapacity: pulumi.Int(1),
Attributes: dynamodb.TableAttributeArray{
&dynamodb.TableAttributeArgs{Name: pulumi.String("id"), Type: pulumi.String("S")},
},
})
_, err := dynamodb.NewGlobalTable(ctx, "myTable", &dynamodb.GlobalTableArgs{
Name: pulumi.String("myTable"),
Replicas: dynamodb.GlobalTableReplicaArray{
&dynamodb.GlobalTableReplicaArgs{RegionName: pulumi.String("us-east-1")},
&dynamodb.GlobalTableReplicaArgs{RegionName: pulumi.String("eu-west-1")},
},
}, pulumi.DependsOn([]pulumi.Resource{usTable, euTable}))TableItemProvides a DynamoDB table item resource.
Note:
TableItemis not designed for managing large amounts of data. Use regular DynamoDB API calls or AWS Data Pipeline for bulk operations. Perform regular backups of all table data.
Note: Items cannot be imported. The
hash_keyandrange_keyvalues in theitemJSON are mapped internally by stripping non-letter characters, which can cause naming collisions (e.g.,your-name-hereandyournamehere).
func NewTableItem(
ctx *pulumi.Context,
name string,
args *dynamodb.TableItemArgs,
opts ...pulumi.ResourceOption,
) (*dynamodb.TableItem, error)TableItemArgs Fieldstype TableItemArgs struct {
// Name of the table to add the item to. Required.
TableName pulumi.StringInput
// Hash key value for the item. Required.
HashKey pulumi.StringInput
// Range key value for the item. Required if the table has a range key.
RangeKey pulumi.StringPtrInput
// JSON representation of the item's attribute name/value pairs.
// Must include the primary key attributes at minimum.
Item pulumi.StringInput
// AWS region override.
Region pulumi.StringPtrInput
}TableItem Output Attributes| Field | Type | Description |
|---|---|---|
TableName | pulumi.StringOutput | Name of the containing table |
HashKey | pulumi.StringOutput | Hash key value |
RangeKey | pulumi.StringPtrOutput | Range key value |
Item | pulumi.StringOutput | JSON item data |
table, _ := dynamodb.NewTable(ctx, "example", &dynamodb.TableArgs{
Name: pulumi.String("example-table"),
ReadCapacity: pulumi.Int(10),
WriteCapacity: pulumi.Int(10),
HashKey: pulumi.String("id"),
Attributes: dynamodb.TableAttributeArray{
&dynamodb.TableAttributeArgs{
Name: pulumi.String("id"),
Type: pulumi.String("S"),
},
},
})
_, err := dynamodb.NewTableItem(ctx, "record", &dynamodb.TableItemArgs{
TableName: table.Name,
HashKey: table.HashKey,
Item: pulumi.String(`{
"id": {"S": "abc123"},
"name": {"S": "Example Item"},
"score": {"N": "42"}
}`),
})LookupTable — Table Data SourceLook up an existing DynamoDB table by name.
func LookupTable(
ctx *pulumi.Context,
args *dynamodb.LookupTableArgs,
opts ...pulumi.InvokeOption,
) (*dynamodb.LookupTableResult, error)LookupTableArgs Fieldstype LookupTableArgs struct {
// Name of the DynamoDB table. Required.
Name string `pulumi:"name"`
// AWS region override.
Region *string `pulumi:"region"`
// Server-side encryption filter.
ServerSideEncryption *GetTableServerSideEncryption `pulumi:"serverSideEncryption"`
// Tags to filter by.
Tags map[string]string `pulumi:"tags"`
}table, err := dynamodb.LookupTable(ctx, &dynamodb.LookupTableArgs{
Name: "my-existing-table",
})
if err != nil {
return err
}
ctx.Export("tableArn", pulumi.String(table.Arn))
ctx.Export("tableStreamArn", pulumi.String(table.StreamArn))Tables are imported using the table name:
pulumi import aws:dynamodb/table:Table basic dynamodb-table-1Global Tables V1 are imported using the global table name:
pulumi import aws:dynamodb/globalTable:GlobalTable MyTable MyTableTable items cannot be imported.
Install with Tessl CLI
npx tessl i tessl/golang-github-com-pulumi-pulumi-aws-sdk-v7docs