Can Python Run on Lambda Web Functions? I Tried It for Fun
A fun experiment running FastAPI on Lambda Web Functions, which only supports Node.js 24, by handing off from index.js to a bundled Python with process.execve().
Introduction
AWS announced Lambda Web Functions on October 12, 2026.
Put simply, it lets you run an existing web app on Lambda as-is.
At the moment, Node.js 24 is the only supported runtime. Python isn't supported.
While catching up on news on X as usual, I came across a post about running a Go app on Web Functions. This article is just a fun experiment: I saw that and tried the same thing with Python.
Since this is just for fun and not an official approach, please don't use it in production!
What are Lambda Web Functions?
Web Functions let you run an HTTP server directly on Lambda. If I had to pick a few highlights, they'd be these:
- One execution environment can handle up to 128 requests concurrently
- You're billed only for the CPU time you actually use, which suits APIs that spend a lot of time waiting on I/O (memory is billed for as long as the execution environment exists)
- A single
aws lambda-web deploycommand takes you from deployment all the way to an HTTPS URL
Your web app listens on the host and port that Lambda passes in through the
AWS_LAMBDA_HTTP_ENDPOINT environment variable.According to the announcement blog post , the runtime is "Node.js 24 on Arm64", so Python simply isn't an option.
How do you run something other than Node.js?
- Lambda loads
/var/task/index.js
- It waits until the port given in
AWS_LAMBDA_HTTP_ENDPOINTaccepts TCP connections
- Once the port is listening, the runtime interface client (RIC, the behind-the-scenes program that talks to Lambda) POSTs to
/2025-09-01/readyto signal that it's ready
The trick is
process.execve() , available in Node.js 24, which replaces the running Node process entirely with another program.If you execve into another program at the very top of index.js, Node is swapped out for that program. However, the RIC, which is responsible for the ready notification, disappears along with Node, so the replacement program has to send the ready notification itself.
Let's try this with Python!
Running FastAPI on Lambda Web Functions
It's a bit of a brute-force approach, but we'll pack the Python interpreter itself into the ZIP for the Node.js 24 execution environment. The final directory layout looks like this:
py-fastapi/
├── pyproject.toml # Dependencies managed by uv
├── uv.lock
└── app/ # Deploy this whole directory
├── index.js # Just execve into Python
├── launcher.py # Ready notification and uvicorn startup
├── main.py # The FastAPI app
├── python/ # Standalone Python (arm64)
└── deps/ # Dependencies such as FastAPICreate the project with uv
uv init --bare py-fastapi --python 3.13
cd py-fastapi
uv add fastapi uvicornDownload the Python interpreter
Web Functions only run on arm64, so I use curl to download the Arm64 build and unpack it into the app directory.
curl -fL -o python.tar.gz \
https://github.com/astral-sh/python-build-standalone/releases/download/20250807/cpython-3.13.6%2B20250807-aarch64-unknown-linux-gnu-install_only_stripped.tar.gz \
&& tar -xzf python.tar.gz -C app \
&& rm python.tar.gz \
&& file app/python/bin/python3.13Install the dependencies
Export requirements.txt from
uv.lock , then install arm64 wheels into app/deps . Some packages, such as pydantic-core, include native extensions, so specifying the platform is a must.uv export --frozen --no-dev --no-hashes -o requirements.txt
uv pip install --target app/deps \
--python-platform aarch64-manylinux2014 \
--python-version 3.13 \
--only-binary :all: \
-r requirements.txtThe app itself (main.py)
This is just a test to see whether it runs, so this is plenty!
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"message": "hello from python"}A launcher with the ready notification (launcher.py)
This takes over what the Node side would normally do. A separate thread waits for the port to open, then sends the ready notification in place of the RIC.
import os, socket, threading, time, urllib.request
import uvicorn
from main import app
host, port = os.environ["AWS_LAMBDA_HTTP_ENDPOINT"].split(":")
def notify_ready():
while True:
try:
socket.create_connection(("127.0.0.1", int(port)), 0.1).close()
break
except OSError:
time.sleep(0.01)
url = f"http://{os.environ['AWS_LAMBDA_RUNTIME_API']}/2025-09-01/ready"
req = urllib.request.Request(url, data=b"{}", method="POST",
headers={"Content-Type": "application/json"})
urllib.request.urlopen(req).close()
threading.Thread(target=notify_ready, daemon=True).start()
# The grace period after SIGTERM is about 1 second, so wait at most 0.9 seconds on shutdown
uvicorn.run(app, host=host, port=int(port), timeout_graceful_shutdown=0.9)index.js
execve into Python, passing the Python path and
PYTHONPATH . Setting PYTHONUNBUFFERED makes logs show up in CloudWatch right away.const PY = "/var/task/python/bin/python3.13";
process.execve(PY, [PY, "/var/task/launcher.py"], {
...process.env,
PYTHONPATH: "/var/task/deps:/var/task",
PYTHONUNBUFFERED: "1",
});The key point is that the first element of the second argument (argv[0]) is also a full path.
At first I passed just the file name,
["python3.13", ...] . The deployment succeeded, but requests returned 502 Bad Gateway, and the logs showed this error:Fatal Python error: Failed to import encodings module
ModuleNotFoundError: No module named 'encodings'Python uses the value of argv[0] to locate its standard library, so with only a file name it couldn't find it and crashed right after starting.
Deploy
aws lambda-web deploy --name py-fastapi --code ./app --create --include-hidden-filesWhen I first ran this without
--include-hidden-files , the deployment warned that 3 hidden files ( lib-dynload/.empty , deps/.lock , deps/fastapi/.agents ) had been excluded, so I added the flag.On success, you get back a URL like
https://xxxx.lambda-web.<region>.on.aws .For an app this small, the package was about 34 MB zipped and about 94 MB unzipped. The deployment package limit is 512 MB unzipped, so there's still plenty of room.
Testing it
curl https://xxxx.lambda-web.<region>.on.aws/{"message":"hello from python"}I sent 3 requests, and all 3 returned this response with status 200.
Here are the results, measured against the Tokyo Region:
Item | Result |
|---|---|
Cold start | About 1.7–1.8 s (CPU time about 1.5 s) |
Reusing the connection (keep-alive) | Median about 30 ms |
New connection every time (including TLS) | About 125–180 ms |
Most of the cold start time went to starting Python and importing FastAPI and pydantic. Once warm, it's plenty fast for a regular API.
Note that the initialization timeout , the time your server has to start listening, is 10 seconds. There's plenty of headroom here, but it could start to matter as you add libraries with heavy imports.
Wrap-up
It ran surprisingly easily.
The mechanism turned out to be simple: "hand everything over to Python from index.js, and send only the ready notification yourself."
That said, if you want to run Python in production today, I think the safe choice is still classic Lambda (Event Functions) combined with the Lambda Web Adapter. Aidan also predicts in his post that AWS will release more runtimes soon. I can't wait for official Python support!
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article