Remote MCP server with an IAM-protected backend API on AWS Lambda Web Functions

MCP client → MCP server → CPU API (IamAuth)

Run a remote MCP server as an AWS Lambda Web Function that calls an existing HTTP API on a second Web Function, protected with IamAuth and SigV4.

This pattern deploys two AWS Lambda Web Functions. The first is a remote MCP server that speaks MCP over Streamable HTTP at /mcp. The second is a plain HTTP API with no MCP code, standing in for a service you already run.
The API's endpoint uses the IamAuth auth type, so Lambda only forwards requests signed with AWS Signature Version 4 by a principal that has lambda:InvokeWebFunctionEndpoint. The MCP server signs each request with its own execution role, whose policy allows invoking only that endpoint. Lambda removes the Authorization header after validating the signature, so the API code does no authentication of its own.
The MCP server exposes two tools. get_current_time runs in the MCP server. run_cpu_work calls the API, which runs 1-20 seconds of SHA-256 hashing and streams a JSON line every second. The MCP server relays each line to the MCP client as a progress notification over a Server-Sent Events stream, and a client cancel closes the backend connection and stops the work.
Running the CPU work in its own function keeps the MCP server responsive and lets each function scale on its own. The MCP server endpoint uses the ApplicationManaged auth type, which makes it public. Add authentication to it before using this pattern outside a demo.

< Back to all patterns
AWS Top Pick

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/lambda-web-mcp-server/nodejs/awscli

Deploy

Set a name prefix, <code>export STACK=lambda-web-mcp-server</code>, then deploy the API: <code>aws lambda-web deploy --name $STACK-cpu-api --code cpu-api --timeout-seconds 60</code>.Switch its endpoint to IamAuth: <code>aws lambda-web update-web-function-endpoint --function-name $STACK-cpu-api --endpoint-name dev --auth-type IamAuth</code>.See the GitHub repo for creating the MCP server's execution role and deploying the MCP server.


Testing

See the GitHub repo for detailed testing instructions.

Cleanup

Delete both functions and their endpoints: aws lambda-web delete-web-function --function-name $STACK-mcp and aws lambda-web delete-web-function --function-name $STACK-cpu-api.
See the GitHub repo for removing the execution roles and log groups.

Created by:

Julian Wood

Julian Wood

Julian is a developer advocate at AWS who loves helping developers learn how serverless and AI technologies can transform the way they build and run applications in the cloud.

Follow on LinkedIn