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 https://github.com/aws/jsii/issues/826
from aws_cdk_dynamodb_seeder import Seeder
my_table = Table(stack, "MyTable",
    table_name="MyTable",
    partition_key={"name": "Id", "type": AttributeType.STRING}
)
Seeder(stack, "MySeeder",
    table=my_table,
    setup=require("./items-to-put.json"),
    teardown=require("./keys-to-delete.json"),
    refresh_on_update=True
)

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

Versioning

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)

Internals

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.56.1.tar.gz (6.8 MB view details)

Uploaded Source

Built Distribution

aws_cdk_dynamodb_seeder-1.56.1-py3-none-any.whl (6.8 MB view details)

Uploaded Python 3

File details

Details for the file aws-cdk-dynamodb-seeder-1.56.1.tar.gz.

File metadata

  • Download URL: aws-cdk-dynamodb-seeder-1.56.1.tar.gz
  • Upload date:
  • Size: 6.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.8

File hashes

Hashes for aws-cdk-dynamodb-seeder-1.56.1.tar.gz
Algorithm Hash digest
SHA256 ade25c206273e8dd302c3e4c1ebba3b95b3444a5afd3107e0447f2a2f9201cf4
MD5 07151979f0b3309e68626cc599991246
BLAKE2b-256 b3ca732383e364358bc2a02b7ad57c1df6c2b2c5a8e173008ef819b5d89d678c

See more details on using hashes here.

File details

Details for the file aws_cdk_dynamodb_seeder-1.56.1-py3-none-any.whl.

File metadata

  • Download URL: aws_cdk_dynamodb_seeder-1.56.1-py3-none-any.whl
  • Upload date:
  • Size: 6.8 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.8

File hashes

Hashes for aws_cdk_dynamodb_seeder-1.56.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e8217c256ce9149ef61738465d79d2d6704696e4b34c25f3e87896590dfc1412
MD5 b05b73a40cdc7bc506824dd53620700e
BLAKE2b-256 4d5d91e5c160a61917e7855fbb39675db7cc0af1523d429fdb95aa4d16fdc84a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page