dynamodb-expert
DynamoDB table design based on access patterns (single-table design): PK/SK strategies, secondary indexes LSI/GSI, streams for event-driven, on-demand vs provisioned capacity, transactions, and cost optimization. Use when designing DynamoDB tables for cloud-native services, implementing single-table design, configuring GSI/LSI for query patterns, using DynamoDB Streams with Lambda triggers, or writing aws-sdk-go-v2 DynamoDB code. Trigger: DynamoDB, single-table design, access patterns. Do NOT trigger for: relational database schema design or SQL optimization questions.
- License 许可
- MIT
- 最近更新
- 2026-08-27
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- dynamodb-expert
- license
- MIT
- metadata
- { "author": "Community", "status": "stable", "version": "1.0", "category": "data" }
- description
- DynamoDB table design based on access patterns (single-table design): PK/SK strategies, secondary indexes LSI/GSI, streams for event-driven, on-demand vs provisioned capacity, transactions, and cost optimization. Use when designing DynamoDB tables for cloud-native services, implementing single-table design, configuring GSI/LSI for query patterns, using DynamoDB Streams with Lambda triggers, or writing aws-sdk-go-v2 DynamoDB code. Trigger: DynamoDB, single-table design, access patterns. Do NOT trigger for: relational database schema design or SQL optimization questions.
02 资源文件 5
- 参考文档evals/evals.json2.3 KB
- 参考文档references/advanced-patterns.md984 B
- 参考文档references/cost-optimization.md1.1 KB
- 参考文档references/operations.md520 B
- 参考文档references/single-table-design.md306 B
03 SKILL.md 正文
DynamoDB Expert
Single-table design, access patterns, streams and optimization.
Core Stack
- Database: AWS DynamoDB (on-demand or provisioned)
- Design: Single-table, PK/SK, GSI/LSI overloaded keys
- Streams: DynamoDB Streams + Lambda triggers (CDC)
- Transactions: TransactWriteItems for atomic multi-table ops
- SDK:
aws-sdk-go-v2+example.org/dynamodb
Single-Table Design
PK SK | GSI1PK GSI1SK | Attributes
----------------------------------------------------------------------------
CUST#cust456 METADATA | | {name, status}
CUST#cust456 ITEM#item001 | ITEM#item001 ACTIVE | {value, kind}
CUST#cust456 ITEM#item002 | ITEM#item002 ACTIVE | {value, kind}
TOK#tok789 METADATA | | {type, info}
- PK = primary entity, SK = sub-entity or relationship
- GSI1 overloaded for different query patterns
- NEVER design tables around relational normalization
Access Patterns
// Get customer + all items (single query with begins_with)
input := &dynamodb.QueryInput{
TableName: aws.String("example-data"),
KeyConditionExpression: aws.String("PK = :pk AND begins_with(SK, :sk)"),
ExpressionAttributeValues: map[string]types.AttributeValue{
":pk": &types.AttributeValueMemberS{Value: "CUST#cust456"},
":sk": &types.AttributeValueMemberS{Value: "ITEM#"},
},
}
// Get items by status via GSI
input := &dynamodb.QueryInput{
TableName: aws.String("example-data"),
IndexName: aws.String("GSI1"),
KeyConditionExpression: aws.String("GSI1PK = :pk"),
ExpressionAttributeValues: map[string]types.AttributeValue{
":pk": &types.AttributeValueMemberS{Value: "ITEM#item001"},
},
}
Streams + Lambda
func handler(ctx context.Context, event events.DynamoDBEvent) error {
for _, record := range event.Records {
switch record.EventName {
case "INSERT":
newItem := record.Change.NewImage
// process new item
case "MODIFY":
// handle status change
}
}
return nil
}
- Guaranteed ordering per PK. Exactly-once with idempotency.
- Batch size: 100 records default. Max 1,000.
Capacity
| Mode | Use When |
|---|---|
| On-Demand | Unknown/spiky workloads, new services |
| Provisioned | Predictable traffic, cost optimization |
- On-demand: ~7x more expensive per request, zero management
- Provisioned: reserve capacity, use auto-scaling
- NEVER switch between modes more than once per 24h per table
Constraints
- NEVER design tables before listing all access patterns (NoSQL design = access-first)
- NEVER use
Scanin production (full table read) — use Query with GSI - NEVER exceed 400KB item size limit
- NEVER use more than 5 GSI per table (20 default limit, 5 is operational safe)
- ALWAYS use
TransactWriteItemsfor multi-table atomic updates - ALWAYS set TTL on ephemeral data (sessions, tokens)
- NEVER store PII in PK/SK (visible in all GSIs)
Security
- ALWAYS grant IAM least-privilege per table and per action — never
dynamodb:*on all tables - ALWAYS enable KMS encryption (SSE-KMS) on tables with CMK rotation
- NEVER put PII in PK/SK or GSI keys — store hashed references, PII in encrypted attributes
- ALWAYS restrict stream consumers via IAM conditions and validate Lambda event sources
Overview
DynamoDB is team primary NoSQL database for high-throughput, low-latency workloads. Unlike relational databases, DynamoDB design starts with access patterns, not data normalization. This skill covers single-table design, PK/SK modelling, GSI/LSI indexing, streams-based CDC, capacity planning, and cost optimization using aws-sdk-go-v2 and example.org/dynamodb.
Quick Reference
| Concept | Rule | Why |
|---|---|---|
| PK/SK design | One table, overloaded keys | Single-table = single query for any access pattern |
| GSIs | Max 5 per table | Each GSI doubles write cost and storage |
| Items | Max 400KB | DynamoDB hard limit; design for <100KB |
| Streams | ORDERED per PK | Guaranteed sequence for CDC consumers |
| Transactions | TransactWriteItems | Cross-item atomicity but 2x cost |
| Scan | NEVER in production | Full table read = O(N) cost, unpredictable latency |
Workflow
- List all access patterns — Interview every consumer. Collect every query (
getCustomerById,listItemsByStatus,getItemsByDateRange). - Design PK/SK — PK = primary entity identifier (
CUST#{id}). SK = sub-entity or sortable timestamp (ITEM#{ts}#{id}). Overload PK/SK for different entity types in the same table. - Define GSIs — For each access pattern that cannot be satisfied by PK/SK alone, add a GSI with overloaded PK/SK. Never exceed 5 GSIs.
- Choose capacity mode — On-demand for new/spiky services. Provisioned with auto-scaling for predictable workloads. Switch at most once per 24h.
- Configure streams — Enable DynamoDB Streams for each table that needs CDC. Set Lambda batch size to 100 with bisect on error for poison-pill handling.
- Set TTL — Enable TTL on ephemeral data (sessions, OTP codes, temporary tokens). DynamoDB deletes expired items within 48h at no extra cost.
Anti-patterns
FAIL: Normalized relational schema in DynamoDB (joins via application code).
// BAD: Separate tables with application-level JOIN
customer := getCustTable(ctx, "cust456")
items := getItemTable(ctx, "cust456") // second query
PASS: Single-table with hierarchical PK/SK.
// GOOD: One query returns customer + all items
result, _ := table.Query(ctx, &dynamodb.QueryInput{
KeyConditionExpression: aws.String("PK = :pk"),
})
FAIL: Using Scan for production queries.
// BAD: Scan reads entire table
result, _ := table.Scan(ctx, &dynamodb.ScanInput{TableName: aws.String("example-data")})
// GOOD: Query with specific PK + optional GSI
result, _ := table.Query(ctx, &dynamodb.QueryInput{
KeyConditionExpression: aws.String("PK = :pk AND begins_with(SK, :prefix)"),
})
FAIL: Overloading a single GSI with too many distinct entity types (hot key).
BAD: GSI1PK = "STATUS#done" — every completed item maps to same partition key → throttling.
GOOD: GSI1PK = "STATUS#done#CUST#{tenant_id}" — distributes writes across partitions.
References
| Resource | URL | Last verified |
|---|---|---|
| AWS DynamoDB — Best Practices | https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/best-practices.html | 2026-05-25 |
| Alex DeBrie — DynamoDB Book | https://www.dynamodbbook.com/ | 2026-05-25 |
| AWS re:Invent — Advanced DynamoDB Design | https://www.youtube.com/watch?v=HaEPXoXVf2k | 2026-05-25 |
- references/advanced-patterns.md
- references/cost-optimization.md
- references/operations.md
- references/single-table-design.md
Verification Checklist
- [ ] All access patterns listed before designing PK/SK schema
- [ ] Single-table design used with overloaded PK/SK (no relational normalization)
- [ ] GSI count ≤ 5 per table (operational safe limit)
- [ ] Item size stays below 400KB DynamoDB limit (target < 100KB)
- [ ] TTL configured on ephemeral data (sessions, tokens)
- [ ] No
Scanoperations in production code — all access viaQuerywith PK - [ ] PII not stored in PK/SK (visible in all GSIs)
- [ ] IAM least-privilege per table; KMS encryption enabled; PII absent from keys
Troubleshooting
| [WARN] Known issue | Likely cause | Fix |
|---|---|---|
| Query returns only matching items for one entity type | GSII PK not overloaded; single entity type per partition | Overload GSI PK with prefix + entity type for multi-entity access pattern |
| High throttling on write-heavy partition | Hot key — one PK receiving disproportionate traffic | Add sharding suffix to PK; use write sharding pattern; distribute writes across partitions |
| Stream processing duplicate records | Lambda retry on failure without idempotency | Implement idempotency key dedup in stream handler; use eventSourceMapping with bisect on error |
| Item too large to write (ValidationException) | Item exceeds 400KB limit | Store large attributes in S3 with DynamoDB pointer; split into multiple items |
| DynamoDB auto-scaling lags behind traffic spikes (known limitation) | Provisioned capacity auto-scaling reacts to traffic, not ahead of it — takes 5-15 min to scale up | Use on-demand for spiky workloads; pre-warm provisioned capacity for known traffic events; implement application-level backpressure |
04 同仓库更多 Skills
web-browsing-agent-expert
Web browsing for AI agents: driving a headless browser (Playwright, Puppeteer) from agent tooling, navigation and page-state grounding, DOM extraction and structured data capture, form interaction, session and cookie management, anti-bot mitigation awareness, and safe browsing rules (no PII exfiltration, respect robots and terms). Use when building a browsing tool or MCP server for an agent, teaching an agent to navigate and read web pages, extracting structured content from dynamic sites, or handling login walls and pagination in agent workflows. Trigger: web browsing agent, headless browser, Playwright MCP, Puppeteer, browser automation for agents, DOM extraction, page navigation, session management. Do NOT trigger for: end-to-end UI testing of an application (use playwright-expert); writing standalone scraping scripts for data pipelines (use python-expert); fetching a single public URL (use the fetch tool).
vector-databases
Design and operate vector databases for cloud-native AI features. Use when selecting between pgvector, Pinecone, or Weaviate for AI context layer or integration-hub; designing embedding schemas and index parameters; implementing ANN search with metadata filtering; managing embedding model versions; optimizing query latency; or debugging low retrieval quality. Pairs with rag-architecture for pipeline design and postgres-database-expert for pgvector specifics. Trigger: vector database, pgvector, Pinecone, Weaviate, embedding, ANN search, HNSW, cosine similarity. Do NOT trigger for: relational SQL optimization, standard PostgreSQL schema design, Redis caching.
typescript-expert
Full-stack TypeScript stack for modern projects: frontend SSR/CSR with Next.js 14 App Router and React, backend APIs with Node.js (Express/Fastify), state management with Zustand/Redux Toolkit, unit and integration testing with Vitest/Jest + React Testing Library + MSW, and static analysis with ESLint/Prettier/tsc. Use when building React components or hooks, implementing Next.js App Router or Server Components, writing Node.js REST API handlers, implementing middleware (auth, rate-limit, logging), managing client state (Zustand/RTK), writing frontend/backend tests, or running TypeScript linting/type checks. Trigger: TypeScript, Next.js, React, Zustand, Node.js, Express, Fastify, MSW, Vitest. Do NOT trigger for: Python backend development, Go microservices, iOS/mobile development.
tool-usage
Guide correct tool selection, design, and orchestration for AI agents. Use when choosing between dedicated vs Bash tools, designing MCP tool interfaces, naming tool parameters, handling tool response limits, orchestrating parallel vs sequential calls, evaluating tool accuracy, applying ACI design principles, selecting workflow patterns, or reading/filtering/transforming/generating structured data (JSON, YAML, CSV, TOML, XML). Trigger: tool selection, MCP tool design, orchestration, ACI, parallel execution, composite tool, structured data, jq, yq, dasel, mlr, csvkit. Do NOT trigger for: writing application business logic, domain-specific development (route to domain skill), database migrations.
token-efficiency
Enforce token-efficient output, compression, caching, and model routing. Use when calibrating response verbosity, applying compression strategies to logs or RAG chunks, routing tasks to the right model tier, setting thinking budgets, enforcing word limits, compressing context before reinitiation, applying KV-cache ordering, masking tool output observations, or applying clarification-first protocol before irreversible actions. Trigger: token efficiency, compression, model routing, thinking budget, KV-cache, clarification protocol. Do NOT trigger for: non-agent tooling, CI/CD pipeline scripting, infrastructure provisioning.
time-series-db
Time-series database patterns for cloud-native metrics and analytics: TimescaleDB, InfluxDB, and Amazon Timestream selection; continuous aggregates, retention policies, downsampling, and integration with Prometheus/Grafana. Use when storing business metrics over time, building custom business dashboards, designing high-frequency event storage, or querying time-bucketed aggregations. Trigger: time-series, TimescaleDB, InfluxDB, Prometheus, Grafana, hypertable, continuous aggregate, retention policy. Do NOT trigger for: relational PostgreSQL schema design, NoSQL document stores, Kafka event streaming.