Serverless AI Agent with AgentCore MCP Gateway and OpenAPI Target

AWS Lambda → Amazon Cognito → Amazon Bedrock AgentCore Gateway → WeatherAPI.com

Strands SDK agent on Lambda uses AgentCore Gateway (MCP) to call WeatherAPI.com via an OpenAPI target with Cognito JWT auth and API key injection.

The user authenticates with Amazon Cognito and receives a JWT token.
The JWT is passed to an Agent Lambda which uses the Strands Agents SDK to create an AI agent backed by Amazon Bedrock (Claude Sonnet 4.5 cross-region inference profile).
The Strands Agent connects to an AgentCore Gateway MCP endpoint, dynamically discovering available weather tools via the MCP tools/list protocol.
The AgentCore Gateway validates the JWT token using a CUSTOM_JWT authorizer backed by Cognito, then routes MCP tool calls directly to WeatherAPI.com via an OpenAPI target.
The OpenAPI target is defined inline in the SAM template using the WeatherAPI.com OpenAPI schema. The Gateway injects the API key automatically using an API Key Credential Provider backed by AWS Secrets Manager — no Lambda intermediary required.
The Strands SDK handles the full agentic loop: tool discovery, Claude tool selection, tool execution via the Gateway, and response formatting — all in a single agent() call.
The stack is built and deployed with AWS SAM (sam build + sam deploy). The model used by the agent is configurable via the --model-id flag on the deploy script, which sets the BedrockModelId template parameter.

< Back to all patterns

GitHub icon Download this pattern (.zip)

GitHub icon View this pattern on GitHub


Clone repo

git clone https://github.com/aws-samples/serverless-patterns/cd serverless-patterns/strands-agentcore-openapi

Deploy

./scripts/deploy.sh --environment-name dev --weather-api-key YOUR_WEATHERAPI_KEY


Testing

./scripts/test.sh
./scripts/test.sh 'What is the weather in London?'
./scripts/test.sh 'What is the weather in Paris, France?'
./scripts/test.sh 'Is it raining in New York right now?'

Cleanup

sam delete --stack-name dev-openapi-agent-gateway --region us-east-1

Created by:

Mike Hume

Mike Hume

AWS Senior Solutions Architect & UKPS Serverless Lead.

Follow on LinkedIn