Skip to content

New serverless pattern - apigw-streaming-lambda-bedrock-cdk#3054

Open
NithinChandranR-AWS wants to merge 3 commits intoaws-samples:mainfrom
NithinChandranR-AWS:NithinChandranR-AWS-feature-apigw-streaming-lambda-bedrock-cdk
Open

New serverless pattern - apigw-streaming-lambda-bedrock-cdk#3054
NithinChandranR-AWS wants to merge 3 commits intoaws-samples:mainfrom
NithinChandranR-AWS:NithinChandranR-AWS-feature-apigw-streaming-lambda-bedrock-cdk

Conversation

@NithinChandranR-AWS
Copy link
Copy Markdown

New Serverless Pattern: API Gateway REST Streaming with Lambda and Amazon Bedrock

Description

Deploys an API Gateway REST API with response streaming enabled, backed by a Lambda function that streams responses from Amazon Bedrock (Claude) in real-time using Server-Sent Events (SSE). Time-to-first-byte is typically under 1 second.

Architecture

Client (curl) → API Gateway REST (Stream) → Lambda (Streaming) → Bedrock (Claude)
← SSE ← ← chunked ← ← stream ←

Key Features

  • ResponseTransferMode: STREAM via CfnMethod escape hatch
  • /response-streaming-invocations URI for Lambda streaming
  • awslambda.streamifyResponse() wrapper in Lambda handler
  • Real-time token-by-token streaming to client

Framework / Language

  • AWS CDK (TypeScript)
  • Lambda runtime: Node.js 20.x

Testing

  • Includes curl command for real-time streaming test
  • CDK synth verified (17 CloudFormation resources)

…-cdk

- Fix Bedrock model ID default (add -v1:0 suffix for inference profile)
- Use L2 addMethod + escape hatches for streaming (fixes CDK validation)
- Add ResponseTransferMode and streaming URI via property overrides

Tested: CDK synth verified, deployed to AWS account
Replace wildcard resource with inference profile ARN and
foundation-model/* to follow least-privilege IAM best practices.
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