CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/golang-github-com-pulumi-pulumi-aws-sdk-v7

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.

Overview
Eval results
Files

dynamodb.mddocs/reference/database/

Amazon DynamoDB

The dynamodb package provides resources for managing Amazon DynamoDB tables, global tables, table items, replicas, indexes, streams, and related features.

Import

import "github.com/pulumi/pulumi-aws/sdk/v7/go/aws/dynamodb"

Available Resources and Data Sources

// 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)

Table

Provides 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 ignoreChanges on readCapacity and/or writeCapacity if an autoscaling policy is attached. Use ignoreChanges on replica when managing replicas via dynamodb.TableReplica.

Constructor

func NewTable(
    ctx  *pulumi.Context,
    name string,
    args *dynamodb.TableArgs,
    opts ...pulumi.ResourceOption,
) (*dynamodb.Table, error)

TableArgs Fields

type 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

FieldTypeDescription
Arnpulumi.StringOutputARN of the table
Namepulumi.StringOutputTable name
HashKeypulumi.StringOutputHash (partition) key attribute name
RangeKeypulumi.StringPtrOutputRange (sort) key attribute name
BillingModepulumi.StringPtrOutputBilling mode in use
ReadCapacitypulumi.IntOutputCurrent read capacity units
WriteCapacitypulumi.IntOutputCurrent write capacity units
StreamArnpulumi.StringOutputStream ARN (when StreamEnabled is true)
StreamLabelpulumi.StringOutputStream timestamp label
StreamViewTypepulumi.StringOutputStream view type
TableClasspulumi.StringPtrOutputStorage class

DynamoDB Attribute Types

CodeType
SString
NNumber
BBinary

Example — Provisioned Table with GSI

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
    })
}

Example — On-Demand Table with Streams

_, 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),
    },
})

Example — Global Table V2 with Replicas

_, 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"),
        },
    },
})

GlobalTable

Manages 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 Replicas block on the dynamodb.Table resource instead.

Constructor

func NewGlobalTable(
    ctx  *pulumi.Context,
    name string,
    args *dynamodb.GlobalTableArgs,
    opts ...pulumi.ResourceOption,
) (*dynamodb.GlobalTable, error)

GlobalTableArgs Fields

type 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

FieldTypeDescription
Arnpulumi.StringOutputARN of the DynamoDB Global Table
Namepulumi.StringOutputGlobal table name

Example — Global Table V1 across Two Regions

// 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}))

TableItem

Provides a DynamoDB table item resource.

Note: TableItem is 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_key and range_key values in the item JSON are mapped internally by stripping non-letter characters, which can cause naming collisions (e.g., your-name-here and yournamehere).

Constructor

func NewTableItem(
    ctx  *pulumi.Context,
    name string,
    args *dynamodb.TableItemArgs,
    opts ...pulumi.ResourceOption,
) (*dynamodb.TableItem, error)

TableItemArgs Fields

type 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

FieldTypeDescription
TableNamepulumi.StringOutputName of the containing table
HashKeypulumi.StringOutputHash key value
RangeKeypulumi.StringPtrOutputRange key value
Itempulumi.StringOutputJSON item data

Example

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 Source

Look up an existing DynamoDB table by name.

Function Signature

func LookupTable(
    ctx  *pulumi.Context,
    args *dynamodb.LookupTableArgs,
    opts ...pulumi.InvokeOption,
) (*dynamodb.LookupTableResult, error)

LookupTableArgs Fields

type 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"`
}

Example

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))

Import

Tables are imported using the table name:

pulumi import aws:dynamodb/table:Table basic dynamodb-table-1

Global Tables V1 are imported using the global table name:

pulumi import aws:dynamodb/globalTable:GlobalTable MyTable MyTable

Table items cannot be imported.

Install with Tessl CLI

npx tessl i tessl/golang-github-com-pulumi-pulumi-aws-sdk-v7

docs

index.md

tile.json