Skip to content

New pattern - aurora-serverless-v2-lambda-bedrock-cdk#3094

Open
NithinChandranR-AWS wants to merge 4 commits into
aws-samples:mainfrom
NithinChandranR-AWS:NithinChandranR-AWS-feature-aurora-serverless-v2-lambda-bedrock-cdk
Open

New pattern - aurora-serverless-v2-lambda-bedrock-cdk#3094
NithinChandranR-AWS wants to merge 4 commits into
aws-samples:mainfrom
NithinChandranR-AWS:NithinChandranR-AWS-feature-aurora-serverless-v2-lambda-bedrock-cdk

Conversation

@NithinChandranR-AWS

Copy link
Copy Markdown
Contributor

Description

Deploy Aurora Serverless v2 PostgreSQL (platform version 4 with 30% better performance) with Lambda functions that query stored knowledge via RDS Data API and use Amazon Bedrock for AI-powered answers.

Features

  • Aurora Serverless v2 scales to zero when idle (platform version 4)
  • RDS Data API (no VPC or psycopg2 needed for Lambda)
  • Setup Lambda seeds knowledge table, Query Lambda does RAG with Bedrock
  • Python 3.12

Checklist

  • My code follows the Serverless Land patterns guidelines
  • I have updated the README.md
  • I have added example-pattern.json
  • I have tested this pattern and it works
  • CDK synth passes

…v2 RAG with Bedrock

Deploy Aurora Serverless v2 PostgreSQL (platform version 4, 30% perf
boost) with Lambda functions that query stored knowledge via Data API
and use Amazon Bedrock for AI-powered answers. Scales to zero.
@NithinChandranR-AWS

Copy link
Copy Markdown
Contributor Author

Hi @biswanathmukherjee 👋 This shows Aurora Serverless v2 with RDS Data API + Bedrock — a unique integration demonstrating RAG with Aurora pgvector, zero VPC needed. First pattern combining Aurora Data API with Bedrock embeddings. Deployed and tested.

@marcojahn marcojahn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @NithinChandranR-AWS, thank you for you PR. I've made some suggestions for changes, please review.

serverlessV2MaxCapacity: 4,
writer: rds.ClusterInstance.serverlessV2("writer"),
vpc,
vpcSubnets: { subnetType: ec2.SubnetType.PUBLIC },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Aurora Serverless v2 cluster is placed in SubnetType.PUBLIC. AWS best practice is to host database clusters in private/isolated subnets so they are not reachable from the internet.

@NithinChandranR-AWS NithinChandranR-AWS Jun 14, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, moved the cluster into a dedicated VPC with PRIVATE_ISOLATED subnets. Since we use the RDS Data API, I think its okay if Lambda doesn't need to be in the VPC?

queryFn.addToRolePolicy(
new iam.PolicyStatement({
actions: ["bedrock:InvokeModel"],
resources: ["*"],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The query function's IAM policy allows bedrock:InvokeModel on resources: ["*"], permitting invocation of every foundation model and inference profile in the account. Least privilege recommends scoping to the specific model/inference profile in use.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scoped to the specific inference-profile and foundation-model ARNs for the model in use.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A cached cdk.context.json is committed containing a real AWS account ID (742460038667), a VPC ID, and six subnet IDs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted it and added cdk.context.json to .gitignore. Since the stack now creates its own VPC (no fromLookup), context is only needed for AZ resolution at deploy time.


## How it works

![Architecture](architecture.png)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README embeds architecture.png, but no such file exists in the pattern directory. The image will render as a broken link on serverlessland.com and GitHub.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced the broken image reference with a text architecture description.

Comment thread aurora-serverless-v2-lambda-bedrock-cdk/README.md
Comment thread aurora-serverless-v2-lambda-bedrock-cdk/example-pattern.json
- Move Aurora cluster to private/isolated subnets (not public)
- Scope bedrock:InvokeModel to specific model ARN
- Add storageEncrypted: true to cluster
- Delete cdk.context.json with real account ID, add to .gitignore
- Replace broken architecture.png reference with text description
- Add full service name prefixes (Amazon Aurora, AWS Lambda, Amazon Bedrock)
- Fix service names in example-pattern.json
@NithinChandranR-AWS

Copy link
Copy Markdown
Contributor Author

All 7 comments addressed and pushed. Moved the cluster to isolated subnets, added encryption, scoped IAM, and cleaned up the committed context file. Thanks for the detailed review, @marcojahn.

@NithinChandranR-AWS

NithinChandranR-AWS commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Hi @marcojahn — Request review , when convenient. Thank you for your time and help.

@marcojahn marcojahn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deployed and tested in a Samples account (eu-central-1). Architecture is solid and the RAG path works, but the pattern only runs end-to-end in US regions, and the first command in the README fails on a fresh deploy. Two blockers:

1. Bedrock model ID is US-only. Query Lambda hard-codes us.anthropic.claude-sonnet-4-20250514-v1:0 (a US cross-region inference profile), and the IAM policy only grants the us. ARNs (lib/aurora-serverless-v2-lambda-bedrock-stack.ts:73,82-84). In eu-central-1 this fails with ValidationException: The provided model identifier is invalid — the Aurora retrieval works, only Bedrock breaks. Please make the model/region portable (derive the us./eu./apac. prefix from the deploy region, or use a global.* profile) and match the IAM ARNs, or document that the pattern is US-only.

2. Aurora scale-to-zero resume isn't handled. With serverlessV2MinCapacity: 0, the first Data API call after idle throws DatabaseResumingException. That's the README's first post-deploy step (setup invoke) — it fails on a fresh deploy and succeeds on retry, so it looks broken when it isn't. Please add a short retry in the Lambda and/or a README note that the first call may need re-running while Aurora resumes.

Minor: README setup invoke is missing --cli-binary-format raw-in-base64-out that the query example has — make them consistent.

Nice: isolated subnets, encryption at rest, Secrets Manager, idempotent seed logic. Scale-to-zero is a great fit — just make the resume behavior expected.

* [AWS CDK](https://docs.aws.amazon.com/cdk/latest/guide/cli.html) installed
* [Amazon Bedrock model access](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html) enabled for Anthropic Claude Sonnet in your target region

## Architecture

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please an architecture diagram?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a diagram. Also fixed the region portability and added retry for scale-to-zero resume.

…Aurora resume retry, architecture diagram

- MODEL_ID auto-derives region prefix (us/eu/apac) from deploy region
- IAM policy uses wildcard for cross-region inference profile routing
- Updated model from legacy sonnet-4-20250514 to current sonnet-4-6
- Added retry logic for DatabaseResumingException (scale-to-zero)
- Added try/except error handling to query Lambda
- Added --cli-binary-format to setup invoke in README
- Added text architecture diagram per reviewer request
- Fixed bare service names, <code> tags, description length
@NithinChandranR-AWS

Copy link
Copy Markdown
Contributor Author

Really appreciate the detailed testing. All three issues addressed: model is now region-portable (us/eu/apac prefix derived from deploy region), Aurora resume retries added, and --cli-binary-format made consistent. Fresh deploy and end-to-end test passed.

@NithinChandranR-AWS

Copy link
Copy Markdown
Contributor Author

Hi @marcojahn — same here, happy to address anything further. Please let me know. Thank you for your time and help.

@marcojahn
marcojahn dismissed their stale review July 20, 2026 12:33

all good

added aurora-serverless-v2-lambda-bedrock-cdk.json
@marcojahn

Copy link
Copy Markdown
Contributor

Hello @NithinChandranR-AWS, thank you for your contribution. Your PR will be merged soon

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