@simple-cdk/dynamodb
v4.2.4
Published
simple-cdk adapter: discover model files and create DynamoDB tables with GSIs, streams, and TTL.
Maintainers
Readme
@simple-cdk/dynamodb
simple-cdk adapter that auto-discovers model files and creates DynamoDB tables with GSIs, streams, and TTL.
Install
npm install @simple-cdk/dynamodb @simple-cdk/core aws-cdk-lib constructsConvention
Each model is a .model.ts file under backend/models/:
backend/models/
├── todo.model.ts
├── user.model.ts
└── ...Usage
import { defineConfig } from '@simple-cdk/core';
import { dynamoDbAdapter } from '@simple-cdk/dynamodb';
export default defineConfig({
app: 'my-app',
stages: { dev: { region: 'us-east-1' } },
adapters: [
dynamoDbAdapter({
dir: 'backend/models', // default
match: ['.model.ts', '.model.js'], // file suffixes to scan
stackName: 'data',
}),
],
});Model config
// backend/models/todo.model.ts
import type { DynamoDbModelConfig } from '@simple-cdk/dynamodb';
const todo: DynamoDbModelConfig = {
name: 'todo',
// tableName: 'my-existing-table', // full name override (adopt existing table)
pk: { name: 'id', type: 'string' },
sk: { name: 'sk', type: 'string' }, // optional sort key
gsis: [
{
name: 'byOwner',
pk: { name: 'ownerId' },
sk: { name: 'createdAt' },
projection: 'ALL',
},
],
stream: 'NEW_AND_OLD_IMAGES', // optional stream
ttlAttribute: 'expiresAt', // optional TTL
pointInTimeRecovery: true,
};
export default todo;Cross-adapter lookup
import { getDynamoTable } from '@simple-cdk/dynamodb';
// inside another adapter's wire():
const table = getDynamoTable(ctx, 'todo');
table.grantReadWriteData(myLambda);Full docs at the main repo.
