Skip to content

New serverless pattern - apigw-http-api-lambda-bedrock-dynamodb-vector-search-cdk - #3275

Draft
proton0210 wants to merge 9 commits into
aws-samples:mainfrom
proton0210:proton0210-feature-dynamodb-vector-search-cdk
Draft

New serverless pattern - apigw-http-api-lambda-bedrock-dynamodb-vector-search-cdk#3275
proton0210 wants to merge 9 commits into
aws-samples:mainfrom
proton0210:proton0210-feature-dynamodb-vector-search-cdk

Conversation

@proton0210

@proton0210 proton0210 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add a TypeScript AWS CDK pattern for API Gateway HTTP API, Lambda, Amazon Bedrock embeddings, and native DynamoDB vector search
  • add POST /documents for embedding and storing documents and POST /search for filtered semantic retrieval with SearchVectors
  • use a tenant-scoped composite primary key (tenantId, documentId) so the same document ID can safely exist in different tenants
  • validate required fields, DynamoDB key byte limits, Titan's 50,000-character input limit, metadata lengths, and topK before invoking AWS services
  • add a bounded CloudFormation custom resource that creates, waits for, replaces, and deletes the DynamoDB vector index while native CDK/CloudFormation coverage is unavailable
  • manage all application and custom-resource Lambda log groups in CloudFormation with one-week retention and DESTROY, preventing cleanup leftovers
  • add least-privilege IAM, sample HTTP and Lambda events, complete deployment/testing/cleanup documentation, optional credential-free CI/CD deployment steps, and Serverless Land metadata

Why this pattern is useful

This pattern gives serverless developers a focused starting point for semantic search while keeping embeddings beside operational data in DynamoDB. It is useful because it:

  • removes the need to provision a separate vector database or maintain a change-data-capture synchronization pipeline
  • demonstrates tenant-scoped vector partitions and optional category filters for SaaS, document discovery, product catalog, support, and knowledge-search APIs
  • bridges the current CDK and CloudFormation coverage gap with an idempotent, bounded custom resource for DynamoDB vector-index lifecycle management
  • combines a pay-per-request HTTP API, Lambda compute, Bedrock embeddings, least-privilege IAM, sample events, and deployment tests in a small reusable pattern rather than a full application

The collection currently contains an S3 Vectors RAG example but no native DynamoDB vector-search pattern.

Validation

  • clean Node.js 24 dependency installation, npm run build, npm test, and npm run synth -- --quiet passed
  • all 9 tests passed across 3 suites, covering application behavior, request boundaries, vector-index lifecycle behavior, and synthesized infrastructure
  • repository example-pattern.json schema validation passed; its introduction is 354 words and it contains 4 official resources
  • generated template inspection found 22 resources, all 3 Lambda log groups managed by CloudFormation, no Step Functions resource, and zero wildcard IAM actions or resources
  • exact commit cf375c1adc3f2a81e9a330163604bdf5bbc92602 deployed through the documented interactive npx cdk deploy path to CREATE_COMPLETE
  • both documented HTTP ingests returned 201; semantic search returned both records on the first attempt and ranked the DynamoDB vector-search document first
  • both supplied direct-Lambda events completed with Lambda status 200 and application responses 201 and 200
  • live negative tests returned 400 for oversized model input, a multibyte oversized tenant key, and malformed JSON; an unknown route returned 404
  • the same documentId was stored in a second tenant and its filtered search returned exactly one tenant/category-correct result with zero cross-category matches
  • application and provider logs contained 38 events with zero ERROR, Exception, Request failed, or timeout matches
  • the documented npx cdk destroy path removed the stack; the README confirmation returned [], and post-destroy inventory found zero residual tables, Lambda functions, HTTP APIs, IAM roles, or log groups belonging to the pattern

Notes

  • Serverless Land submission issue: New pattern submission - apigw-http-api-lambda-bedrock-dynamodb-vector-search-cdk #3276
  • The pattern uses an unauthenticated HTTP API for concise demonstration and documents production authorization/CORS considerations.
  • The vector-index provider uses a bounded 13-minute wait intended for the new empty table deployed by this pattern.
  • No account-specific outputs, API endpoints, role ARNs, AWS profiles, credentials, or generated deployment files are included in this PR.
  • npm audit --omit=dev currently reports one high-severity transitive brace-expansion advisory bundled inside aws-cdk-lib@2.263.0; npm cannot replace that bundled dependency automatically, and it is CDK tooling rather than deployed Lambda code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants