Skip to main content

A simple CDK JSON seeder for DynamoDB

Project description

aws-cdk-dynamodb-seeder Mentioned in Awesome CDK

build codecov dependencies Status npm

npm version NuGet version PyPI version Maven Central

A simple CDK JSON seeder for DynamoDB

Why this package

Glad you asked!

Using AWS CDK for automating infrastructure deployments is an amazing way of integrating the development and operations into one process and one codebase.

However, building dev or test environments that come pre-populated with data can be tricky, especially when using Amazon DynamoDB.

How do I use it

Install using your favourite package manager:

yarn add aws-cdk-dynamodb-seeder

Example TypeScript usage

# Example automatically generated without compilation. See
from aws_cdk_dynamodb_seeder import Seeder
my_table = Table(stack, "MyTable",
    partition_key={"name": "Id", "type": AttributeType.STRING}
Seeder(stack, "MySeeder",

For a more in-depth example, see: elegantdevelopment/aws-cdk-dynamodb-seeder-examples.

Importing seed data

Data passed into setup ("Items" to put) or teardown ("Keys" to delete) should be an array of objects (that are, in turn, representations of string to AttributeValue maps).


We will attempt to align the major and minor version of this package with AWS CDK, but always check our release descriptions for compatibility.

We currently support GitHub package.json dependency version (prod)


Behind the scenes we use an AwsCustomResource as a representation of the related table's seed state. The custom resource's event handlers invoke a Function to perform setup and/or teardown actions.

Deploying a stack

On deployment, we write copies of your seed data locally and use a BucketDeployment to write it to an S3 Bucket.

We then create the handler function and custom resource to field seed requests (the onCreate event will immediate fire as the stack deploys, reading the data from the bucket and seeding the table using AWS.DynamoDB.DocumentClient).

Updating a stack

On a stack update, the onUpdate handler is triggered when refreshOnUpdate is true.

This will run AWS.DynamoDB.DocumentClient.delete() on every teardown "Key" followed by AWS.DynamoDB.DocumentClient.put() on every setup "Item".

Destroying a stack

When the stack is destroyed, the event handler's onDelete function will be invoked, providing teardown is set.

This simply runs AWS.DynamoDB.DocumentClient.delete() on every teardown "Key" before destroying the Seeder's resources.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aws-cdk-dynamodb-seeder-1.37.0.tar.gz (6.5 MB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page