Serverless AI Weather Agent with AgentCore Gateway and Amazon API Gateway Target

Amazon Cognito → AWS Lambda → AgentCore Gateway → Amazon API Gateway

Serverless AI weather agent using Strands SDK and AgentCore Gateway with an API Gateway target. Uses MCP, Cognito JWT auth, and key-less Open-Meteo.

The user authenticates with Amazon Cognito and receives a JWT ID token.
The JWT is passed to an Agent Lambda which uses the Strands Agents SDK to create an AI agent backed by Amazon Bedrock (us.anthropic.claude-sonnet-4-6 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.
AgentCore Gateway auto-discovers operations from the API Gateway REST API via GetExportAPI and presents them as MCP tools to the agent.
The AgentCore Gateway validates the incoming JWT token using a CUSTOM_JWT authorizer backed by Cognito.
When the agent selects a tool, AgentCore routes the request to the API Gateway REST API, authenticating with an API key managed by a credential provider backed by Secrets Manager.
The API Gateway proxies the request to Open-Meteo, a free key-less weather API — one path for geocoding (city name to coordinates) and one for the forecast.
The Strands SDK handles the full agentic loop: tool discovery, Claude tool selection, MCP tool execution, and response formatting — all in a single agent() call. For a place name the agent chains both tools: geocode first, then forecast.

< 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-apigw

Deploy

./scripts/deploy.sh --environment-name dev --region us-east-1


Testing

See the README for detailed testing and end-to-end validation instructions.
./scripts/test.sh
./scripts/test.sh 'What is the weather in London, UK?'

Cleanup

aws bedrock-agentcore-control delete-api-key-credential-provider --name dev-weather-apigw-key --region us-east-1
sam delete --stack-name dev-weather-agent --region us-east-1 --no-prompts
aws secretsmanager delete-secret --secret-id dev/apigw-api-key --force-delete-without-recovery --region us-east-1

Created by:

Mike Hume

Mike Hume

AWS Senior Solutions Architect & UKPS Serverless Lead.

Follow on LinkedIn