A simple CDK JSON seeder for DynamoDB
Glad you asked!
Using AWS CDK for automating infratructure 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
import { Seeder } from 'aws-cdk-dynamodb-seeder';
...
const myTable = new Table(stack, "MyTable", {
tableName: "MyTable",
partitionKey: { name: "Id", type: AttributeType.STRING },
});
...
new Seeder(stack, "MySeeder", {
table: myTable,
tableName: "MyTable",
setup: require("./my-seed-data.json")
});
Seed data is imported/deleted via an arrays of objects. Just remember that the objects must match your table's key definitions.