Copied to Clipboard
You can validate the final result by checking the messages:
Step 7: Publishing to LATEST.PUBLISHED for Managed Instances support...
Step 8: Finalizing API Gateway...
Deployment complete!
API Endpoint URL: https://3x10n3uguc.execute-api.us-east-1.amazonaws.com
MCP HTTP URL: https://3x10n3uguc.execute-api.us-east-1.amazonaws.com/mcp
Health Check URL: https://3x10n3uguc.execute-api.us-east-1.amazonaws.com/health
Once the everything is deployed:
xbill@penguin:~/gemini-cli-aws/mcp-lambdami-python-aws$make status
Function Status (mcp-lambda-python-aws):
---------------------------------------------------------------------------------
| GetFunction |
+------------------------------+-------------------------+----------------------+
| LastModified | Name | Status |
+------------------------------+-------------------------+----------------------+
| 2026年05月06日T16:33:26.000+0000| mcp-lambda-python-aws | ActiveNonInvocable |
+------------------------------+-------------------------+----------------------+
Prod Alias Status:
---------------------
| GetAlias |
+-------+-----------+
| Name | Version |
+-------+-----------+
| prod | 28 |
+-------+-----------+
You can then get the endpoint:
xbill@penguin:~/gemini-cli-aws/mcp-lambdami-python-aws$make endpoint
https://3x10n3uguc.execute-api.us-east-1.amazonaws.com
Gemini CLI settings.json
Once you have the deployed endpoint — update the Gemini CLI MCP settings:
{"mcpServers":{"mcp-lambdami-python-aws":{"httpUrl":"https://3x10n3uguc.execute-api.us-east-1.amazonaws.com/mcp/"}}}
Remote MCP Server Testing
Restart Gemini CLI and check for the new MCP tools:
xbill@penguin:~/gemini-cli-aws/mcp-lambdami-python-aws$gemini
▝▜▄ Gemini CLI v0.41.1
▝▜▄
▗▟▀ Signed in with Google /auth
▝▀ Plan: Gemini Code Assist Standard /upgrade
/mcp list
🟢 mcp-lambdami-python-aws - Ready (1 tool)
Tools:
- mcp_mcp-lambdami-python-aws_greet
Then the remote MCP tool in Lambda Managed Instances can be called:
> greet Lambda Managed Instances!
Researching MCP Server Implementation: Reading main.py to understand the greet tool implementation.
✓ ReadFile main.py
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ greet (mcp-lambdami-python-aws MCP Server) {"param":"Lambda Managed Instances"} │
│ │
│ Hello, Lambda Managed Instances! │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ Hello, Lambda Managed Instances!
Gemini CLI can also summarize the deployment:
✦ The Lambda Managed Instances (LMI) deployment in this project is a hybrid setup that combines CloudFormation for infrastructure and AWS CLI for
specialized Lambda configurations. It is designed to provide high-performance, dedicated compute for the MCP server with zero cold starts and
multi-concurrency.
1. Core Architecture
* Compute: Lambda functions run on dedicated EC2 capacity managed by AWS but living in your VPC.
* Networking: A VPC with Public and Private subnets. The Lambda resides in the Private subnet and uses a NAT Gateway for outbound internet
access (required for external tool calls).
* Inbound: API Gateway (HTTP API) acts as the entry point, routing traffic to a Lambda Alias (prod).
2. Infrastructure (CloudFormation)
The template.yaml defines the foundational components:
* VPC & NAT Gateway: Essential for providing the dedicated instances with a secure environment and internet connectivity.
* IAM Roles:
* Execution Role: Standard Lambda permissions + VPC access.
* Operator Role: Allows the Lambda service to manage EC2 resources (Scaling, Patching) on your behalf via the
AWSLambdaManagedEC2ResourceOperator policy.
* API Gateway: Configured with a $default route pointing to the prod alias of the Lambda.
3. Managed Instances Configuration (deploy.sh)
Because LMI features are often newer or require specific CLI sequences, deploy.sh handles the following:
* Capacity Provider: A named resource (mcp-lambda-python-aws-cp) that defines:
* Instance Requirements: Architectures (x86_64) and Scaling (Max vCPU count).
* VPC Placement: Subnets and Security Groups.
* Lambda Function: Created with a capacity-provider-config that links it to the Capacity Provider.
* Memory/vCPU: Set to 2048MB (2GB) minimum to meet LMI requirements.
* Package Type: Image (Container-based using the project's Dockerfile).
4. Deployment Workflow
1. Build & Push: Docker image is built and pushed to Amazon ECR.
2. Infra Deploy: CloudFormation creates the VPC, IAM roles, and API Gateway.
3. CP Setup: The script ensures the Capacity Provider exists and is configured.
4. Function Update/Create: The Lambda function is deployed or updated with the LMI configuration.
5. Versioning:
* A new version is published.
* The prod alias is updated to point to this version.
* LATEST_PUBLISHED support: The function is published to the special LATEST_PUBLISHED state, which is a requirement for LMI to manage
instances effectively.
5. Key Operational Characteristics
* Multi-concurrency: Unlike standard Lambda, LMI handles multiple concurrent requests per instance (default 8), making it ideal for the
persistent connections used in MCP SSE.
* Stateless HTTP: The server uses stateless_http=True in FastMCP, ensuring compatibility with the Lambda lifecycle.
* Warm-up Period: Functions may show as ActiveNonInvocable initially while the Managed Instances are being provisioned and warmed up.
Summary
The strategy for using Python for MCP development with Gemini CLI on Amazon Lambda Managed Instances was validated with a incremental step by step approach.
A minimal HTTP transport MCP Server was started from Python source code and validated with Gemini CLI running as a MCP client in the same local environment.
This MCP server was then wrapped in a Docker container and deployed to Amazon Lambda Instances. The local copy of Gemini CLI was used as a MCP client to validate the connection.
This approach can be extended to more complex deployments using other MCP transports and Cloud based options.