Skip to main content
skill CX Codex

dynamodb-toolbox-patterns — Claude Code skill: typed DynamoDB

A skill with TypeScript patterns for DynamoDB-Toolbox v2: schemas, entities, .build() commands, queries and transactions.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add giuseppe-trisciuoglio/developer-kit --skill dynamodb-toolbox-patterns -a claude-code
Open on GitHub

What dynamodb-toolbox-patterns does

The skill gives your agent working patterns for a DynamoDB access layer built on DynamoDB-Toolbox v2 and the AWS SDK v3 DocumentClient. It covers table and GSI declarations, entities defined with item(), string(), number(), list() and map(), and the modifiers .key(), .required(), .default(), .transform(), .link().

A second block is about commands. PutItemCommand, GetItemCommand, UpdateItemCommand and DeleteItemCommand are assembled through .build() instead of hand-rolled input objects. There are examples of QueryCommand and ScanCommand with a beginsWith range and an index query, plus BatchWriteCommand and TransactWriteCommand for bulk and atomic writes.

You need dynamodb-toolbox, @aws-sdk/client-dynamodb and @aws-sdk/lib-dynamodb installed. Everything here assumes AWS SDK v3, so examples will not compile against a v2 client. Transactions are slower than single-item writes and come with limits, which is worth checking before you wrap every write in one.

What it helps with

  • declare a table and entities with strict TypeScript inference
  • run CRUD through .build() instead of manual command input
  • query a key or GSI with a beginsWith range
  • combine several entities into a batch or transaction write
  • lay out a single-table design with computed keys

Example prompts for the agent

  • Help me define a User entity for DynamoDB-Toolbox v2 with PK/SK keys and a GSI
  • Rewrite my DynamoDB reads as .build(QueryCommand) with a beginsWith range
  • Build a transaction from PutItem and UpdateItem using TransactWriteCommand

How to install dynamodb-toolbox-patterns

1Skills CLI (Vercel)

npx skills add giuseppe-trisciuoglio/developer-kit --skill dynamodb-toolbox-patterns -a claude-code

2Manually: put the files in place

~/.claude/skills/dynamodb-toolbox-patterns/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/dynamodb-toolbox-patterns/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about dynamodb-toolbox-patterns

How do I install dynamodb-toolbox-patterns in Claude?

Run npx skills add giuseppe-trisciuoglio/developer-kit --skill dynamodb-toolbox-patterns -a claude-code. The skill file then lives at ~/.claude/skills/dynamodb-toolbox-patterns/SKILL.md.

What does dynamodb-toolbox-patterns do?

It hands the agent TypeScript patterns for DynamoDB-Toolbox v2: schema and entity modeling, .build() commands, query and scan access paths, batch and transaction operations.

What do I need before using it?

The packages dynamodb-toolbox, @aws-sdk/client-dynamodb and @aws-sdk/lib-dynamodb. The skill is built around the AWS SDK v3 DocumentClient.

Source text

SKILL.md · MIT
---
name: dynamodb-toolbox-patterns
description: Provides TypeScript patterns for DynamoDB-Toolbox v2 including schema/table/entity modeling, .build() command workflow, query/scan access patterns, batch and transaction operations, and single-table design with computed keys. Use when implementing type-safe DynamoDB access layers with DynamoDB-Toolbox v2 in TypeScript services or serverless applications.
allowed-tools: Read, Write, Edit, Glob, Grep, Bash
---

# DynamoDB-Toolbox v2 Patterns (TypeScript)

## Overview

This skill provides practical TypeScript patterns for using DynamoDB-Toolbox v2 with AWS SDK v3 DocumentClient. It focuses on type-safe schema modeling, `.build()` command usage, and production-ready single-table design.

## When to Use

- Defining DynamoDB tables and entities with strict TypeScript inference
- Modeling schemas with `item`, `string`, `number`, `list`, `set`, `map`, and `record`
- Implementing `GetItem`, `PutItem`, `UpdateItem`, `DeleteItem` via `.build()`
- Building query and scan access paths with primary keys and GSIs
- Handling batch and transactional operations
- Designing single-table systems with computed keys and entity patterns

## Instructions

1. **Start from access patterns**: identify read/write queries first, then design keys.
2. **Create table + entity boundaries**: one table, multiple entities if using single-table design.
3. **Define schemas with constraints**: apply `.key()`, `.required()`, `.default()`, `.transform()`, `.link()`.
4. **Use `.build()` commands everywhere**: avoid ad-hoc command construction for consistency and type safety.
5. **Add query/index coverage**: validate GSI/LSI paths for each required access pattern.
6. **Use batch/transactions intentionally**: batch for throughput, transactions for atomicity.
7. **Keep items evolvable**: use optional fields, defaults, and derived attributes for schema evolution.

## Examples

### Install and Setup

```bash
npm install dynamodb-toolbox @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb
```

```typescript
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
import { Table } from 'dynamodb-toolbox/table';
import { Entity } from 'dynamodb-toolbox/entity';
import { item, string, number, list, map } from 'dynamodb-toolbox/schema';

const client = new DynamoDBClient({ region: process.env.AWS_REGION ?? 'eu-west-1' });
const documentClient = DynamoDBDocumentClient.from(client);

export const AppTable = new Table({
  name: 'app-single-table',
  partitionKey: { name: 'PK', type: 'string' },
  sortKey: { name: 'SK', type: 'string' },
  indexes: {
    byType: { type: 'global', partitionKey: { name: 'GSI1PK', type: 'string' }, sortKey: { name: 'GSI1SK', type: 'string' } }
  },
  documentClient
});
```

### Entity Schema with Modifiers and Complex Attributes

```typescript
const now = () => new Date().toISOString();

export const UserEntity = new Entity({
  name: 'User',
  table: AppTable,
  schema: item({
    tenantId: string().required('always'),
    userId: string().required('always'),
    email: string().required('always').transform(input => input.toLowerCase()),
    role: string().enum('admin', 'member').default('member'),
    loginCount: number().default(0),
    tags: list(string()).default([]),
    profile: map({
      displayName: string().optional(),
      timezone: string().default('UTC')
    }).default({ timezone: 'UTC' })
  }),
  computeKey: ({ tenantId, userId }) => ({
    PK: `TENANT#${tenantId}`,
    SK: `USER#${userId}`,
    GSI1PK: `TENANT#${tenantId}#TYPE#USER`,
    GSI1SK: `EMAIL#${userId}`
  })
});
```

### `.build()` CRUD Commands

```typescript
import { PutItemCommand } from 'dynamodb-toolbox/entity/actions/put';
import { GetItemCommand } from 'dynamodb-toolbox/entity/actions/get';
import { UpdateItemCommand, $add } from 'dynamodb-toolbox/entity/actions/update';
import { DeleteItemCommand } from 'dynamodb-toolbox/entity/actions/delete';

await UserEntity.build(PutItemCommand)
  .item({ tenantId: 't1', userId: 'u1', email: '[email protected]' })
  .send();

const { Item } = await UserEntity.build(GetItemCommand)
  .key({ tenantId: 't1', userId: 'u1' })
  .send();

await UserEntity.build(UpdateItemCommand)
  .item({ tenantId: 't1', userId: 'u1', loginCount: $add(1) })
  .send();

await UserEntity.build(DeleteItemCommand)
  .key({ tenantId: 't1', userId: 'u1' })
  .send();
```

### Query and Scan Patterns

```typescript
import { QueryCommand } from 'dynamodb-toolbox/table/actions/query';
import { ScanCommand } from 'dynamodb-toolbox/table/actions/scan';

const byTenant = await AppTable.build(QueryCommand)
  .query({
    partition: `TENANT#t1`,
    range: { beginsWith: 'USER#' }
  })
  .send();

const byTypeIndex = await AppTable.build(QueryCommand)
  .query({
    index: 'byType',
    partition: 'TENANT#t1#TYPE#USER'
  })
  .options({ limit: 25 })
  .send();

const scanned = await AppTable.build(ScanCommand)
  .options({ limit: 100 })
  .send();
```

### Batch and Transaction Workflows

```typescript
import { BatchWriteCommand } from 'dynamodb-toolbox/table/actions/batchWrite';
import { TransactWriteCommand } from 'dynamodb-toolbox/table/actions/transactWrite';

await AppTable.build(BatchWriteCommand)
  .requests(
    UserEntity.build(PutItemCommand).item({ tenantId: 't1', userId: 'u2', email: '[email protected]' }),
    UserEntity.build(PutItemCommand).item({ tenantId: 't1', userId: 'u3', email: '[email protected]' })
  )
  .send();

await AppTable.build(TransactWriteCommand)
  .requests(
    UserEntity.build(PutItemCommand).item({ tenantId: 't1', userId: 'u4', email: '[email protected]' }),
    UserEntity.build(UpdateItemCommand).item({ tenantId: 't1', userId: 'u1', loginCount: $add(1) })
  )
  .send();
```

## Single-Table Design Guidance

- Model each business concept as an entity with strict schema.
- Keep PK/SK predictable and composable (`TENANT#`, `USER#`, `ORDER#`).
- Encode access paths into GSI keys, not in-memory filters.
- Prefer append-only timelines for audit/history data.
- Keep hot partitions under control with scoped partitions and sharding where needed.

## Best Practices

- Design keys from access patterns first, then derive entity attributes.
- Keep one source of truth for key composition (`computeKey`) to avoid drift.
- Use `.options({ consistent: true })` only where strict read-after-write is required.
- Prefer targeted queries over scans for runtime request paths.
- Add conditional expressions for idempotency and optimistic concurrency control.
- Validate batch/transaction size limits before execution to avoid partial failures.

## Constraints and Warnings

- DynamoDB-Toolbox v2 relies on AWS SDK v3 DocumentClient integration.
- Avoid table scans in request paths unless explicitly bounded.
- Use conditional writes for concurrency-sensitive updates.
- Transactions are limited and slower than single-item writes; use only for true atomic requirements.
- Validate key design against target throughput before implementation.

## References

Primary references curated from Context7 are available in:

- `references/api-dynamodb-toolbox-v2.md`

© giuseppe-trisciuoglio · MIT · giuseppe-trisciuoglio/developer-kit

Similar skills

All skills for Data and databases →

From the same set93

aws-lambda-typescript-integration Provides AWS Lambda integration patterns for TypeScript, comparing NestJS and raw handlers with cold start optimization guidelines. CX Codex +1 3,600installs aws-lambda-python-integration Tells the agent how to build and ship Python functions on AWS Lambda: Chalice or raw Python, cold start tuning, API Gateway and ALB wiring. CX Codex +1 3,600installs graalvm-native-image Guides the ahead-of-time compilation of Java applications into native executables with GraalVM. Useful when cutting cold start latency and memory usage in microservices. CX Codex +1 3,500installs memory-md-management This skill scans project memory files such as CLAUDE.md, scores them against six criteria and proposes targeted edits. CX Codex +1 3,500installs github-issue-workflow An 8-phase workflow that takes GitHub issues from description to pull request. It isolates untrusted prompt text, enforces testing, and coordinates code review. CX Codex +1 3,500installs notebooklm A skill that wires your agent to Google NotebookLM through the nlm CLI: query docs, add sources, generate podcasts and reports. CX Codex +1 3,500installs docs-updater The skill diffs your branch against the last release tag and updates README, CHANGELOG and documentation folders. Handy before a release or a pull request. CX Codex +1 3,500installs spring-boot-project-creator Generates a Spring Boot 3.x or 4.x project via Spring Initializr with DDD or layered architecture. Handy when bootstrapping a Java microservice with JPA, OpenAPI, and Docker Compose. CX Codex +1 3,500installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor