AWS CDK DynamoDB Construct Library

raw JSON →
1.204.0 verified Mon Apr 27 auth: no python maintenance

The CDK Construct Library for AWS::DynamoDB provides high-level constructs for defining Amazon DynamoDB tables in AWS CDK applications. Version 1.204.0 is part of the AWS CDK v1 (maintenance mode). Releases follow the CDK release cadence. Note: v1 is in maintenance; prefer CDK v2.

pip install aws-cdk-aws-dynamodb==1.204.0
error ModuleNotFoundError: No module named 'aws_cdk.aws_dynamodb'
cause Missing package installation or using CDK v2 without aws-cdk-lib installed.
fix
For CDK v1: pip install aws-cdk-aws-dynamodb. For CDK v2: pip install aws-cdk-lib.
error jsii.errors.JSIIError: Cannot use "aws-cdk-aws-dynamodb" module without "aws-cdk" module
cause Required dependency aws-cdk.core not installed.
fix
Install core: pip install aws-cdk.core (or for v2, install aws-cdk-lib).
error jsii.errors.JSIIError: Resource of type 'AWS::DynamoDB::Table' already exists in stack
cause Two table constructs with the same logical ID in the same stack.
fix
Ensure each table has a unique logical ID (e.g., by using different construct IDs).
breaking CDK v1 entered maintenance on June 1, 2022, and will end support on June 1, 2023. New features and updates are not released. Migrate to CDK v2.
fix Upgrade to aws-cdk-lib (v2) by changing imports: from aws_cdk.aws_dynamodb import ... (works in both v1 and v2 but v2 requires aws-cdk-lib).
breaking In CDK v2, this library is included in aws-cdk-lib. Installing aws-cdk-aws-dynamodb separately is not supported and may cause conflicts.
fix Use from aws_cdk.aws_dynamodb import ... after installing aws-cdk-lib.
gotcha If you set point_in_time_recovery to True without specifying a billing mode, the table defaults to PROVISIONED with a default read/write capacity (5 each), which may incur costs.
fix Explicitly set billing_mode to BillingMode.PAY_PER_REQUEST to avoid unexpected charges.
deprecated The attribute 'ttlAttribute' has been deprecated. Use 'time_to_live_attribute' instead.
fix Use time_to_live_attribute='timetolive' when defining the table.

Creates a DynamoDB table with a simple partition key and on-demand billing.

import aws_cdk as cdk
from aws_cdk.aws_dynamodb import Table, Attribute, AttributeType, BillingMode

class MyStack(cdk.Stack):
    def __init__(self, scope: cdk.App, id: str, **kwargs):
        super().__init__(scope, id, **kwargs)
        Table(self, 'MyTable',
              partition_key=Attribute(name='id', type=AttributeType.STRING),
              billing_mode=BillingMode.PAY_PER_REQUEST)

app = cdk.App()
MyStack(app, 'MyStack')
app.synth()