
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
aws-cdk-dynamodb-seeder
Advanced tools
A simple CDK JSON seeder for DynamoDB
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.
Install using your favourite package manager:
yarn add aws-cdk-dynamodb-seeder
# 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.
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).
setup
elements should use the format of params.Item
from AWS.DynamoDB.DocumentClient.put()teardown
elements should use the format of params.Key
from AWS.DynamoDB.DocumentClient.delete()We will attempt to align the major and minor version of this package with AWS CDK, but always check our release descriptions for compatibility.
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.
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).
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".
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.
FAQs
A simple CDK JSON seeder for DynamoDB
We found that aws-cdk-dynamodb-seeder demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.