Skip to content

New serverless pattern - lambda-bedrock-mantle-responses-api-cdk#3133

Open
NithinChandranR-AWS wants to merge 1 commit into
aws-samples:mainfrom
NithinChandranR-AWS:NithinChandranR-AWS-feature-lambda-bedrock-mantle-responses-api-cdk
Open

New serverless pattern - lambda-bedrock-mantle-responses-api-cdk#3133
NithinChandranR-AWS wants to merge 1 commit into
aws-samples:mainfrom
NithinChandranR-AWS:NithinChandranR-AWS-feature-lambda-bedrock-mantle-responses-api-cdk

Conversation

@NithinChandranR-AWS

Copy link
Copy Markdown
Contributor

New Serverless Pattern: Amazon Bedrock Mantle Responses API with AWS Lambda (OpenAI SDK Compatible)

Description

Deploys an API Gateway + Lambda function that calls Amazon Bedrock via the OpenAI-compatible Responses API (bedrock-mantle endpoint) using the standard OpenAI Python SDK. Shows customers how to migrate existing OpenAI applications to Bedrock with minimal code changes — just swap the base URL and API key.

Architecture

Client -> API Gateway (POST /ask) -> Lambda (OpenAI Python SDK) -> bedrock-mantle.{region}.api.aws/v1

Key Features

  • First Bedrock Mantle / OpenAI-compatible Responses API pattern in this repo
  • Uses standard OpenAI Python SDK with only base_url and api_key changed
  • No bedrock:InvokeModel IAM permission needed (auth via Bedrock API key)
  • Stateful conversation support via previous_response_id
  • Default model: openai.gpt-oss-120b (OpenAI GPT on Bedrock)
  • try/catch error handling with structured 500 responses

Framework / Language

  • AWS CDK (TypeScript)
  • Lambda: Python 3.12 (OpenAI SDK)

Changes

  • lib/stack.ts — CDK stack: Lambda with bundled openai package, API Gateway REST API, CfnParameter for API key
  • src/index.py — Lambda handler using client.responses.create()
  • src/requirements.txt — openai
  • README.md — Architecture, prerequisites (Bedrock API key generation), deployment, testing with curl
  • example-pattern.json — Pattern metadata

Testing

  • CDK synth verified
  • Deployed to AWS, tested end-to-end via curl
  • Response: {"response": "Amazon Bedrock is a fully managed AWS service...", "model": "openai.gpt-oss-120b", "id": "resp_..."}
  • Error handling verified (invalid model returns structured 500)

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