Codex CLI Agent on AWS Lambda MicroVMs

Your terminal → AWS Lambda MicroVM → Amazon Bedrock → AWS MCP Server

Deploy an AWS Lambda MicroVM with the OpenAI Codex CLI, powered by Amazon Bedrock and reachable through an interactive shell.

This pattern deploys an AWS Lambda MicroVM with the Codex CLI baked into the image. The MicroVM is launched with the SHELL_INGRESS network connector, so you connect over an interactive shell and run codex directly inside the isolated Firecracker VM.
Codex uses its built-in amazon-bedrock model provider, so inference runs on Amazon Bedrock with credentials supplied at runtime by the MicroVM execution role. There is no ChatGPT sign-in, no OPENAI_API_KEY, and no Amazon Bedrock API key stored in the image. Codex is also wired to the AWS MCP Server from the Agent Toolkit for AWS through the MCP Proxy for AWS, which signs each request with AWS Signature Version 4 (SigV4) using the same execution-role credentials, so it can make live AWS API calls, search AWS documentation, and retrieve AWS skills. Access is read-only, enforced by AWS Identity and Access Management (IAM).
The image is Region-agnostic: src/app.py renders the model, MCP endpoint, and Region into the Codex configuration at runtime from the MicroVM environment, at startup and on every run and resume. The MicroVM suspends when idle, resumes on demand, and has a hard maximum lifetime, so treat it as disposable.
See the README in the GitHub repository for deployment steps, design notes, and troubleshooting.

< 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/lambda-microvms-codex-agent/python/cloudformation

Deploy

export AWS_REGION="us-east-2"./deploy.sh


Testing

Connect to the MicroVM over an interactive shell: ./connect.sh <microvm-id> $AWS_REGION
Inside the shell, confirm Codex and run a completion: codex --version then codex exec "Say hello in one word"
Exercise the AWS MCP Server: codex exec "search the AWS documentation for Lambda MicroVMs idle policy"
See the GitHub repo for detailed testing instructions.

Cleanup

MICROVM_ID="<microvm-id>" AWS_REGION="$AWS_REGION" ./cleanup.sh

Created by:

Dmitry Gulin

Dmitry Gulin

Modernization Architect, AWS

Follow on LinkedIn