Reusable AWS CDK (Python) construct for provisioning AWS Lambda MicroVM images and launchers.
Project description
AWS Lambda MicroVM CDK Construct (Python)
A reusable AWS CDK v2 construct (pure Python, 3.11+) for provisioning AWS Lambda MicroVMs — Firecracker-based, VM-isolated, snapshot-fast serverless compute for AI sandboxes, interactive dev environments, and multi-tenant CI. Secure defaults, every AWS knob overridable, plus an escape hatch.
📜 Documentation | Blogs website
Contact details | mailto:ran.isenberg@ranthebuilder.cloud
Status: early development. Repo:
lambda-microvm-cdk-python· PyPI package (planned):lambda-microvm-cdk.
What it does
LambdaMicroVM is a typed wrapper around the L1 AWS::Lambda::MicrovmImage resource. In one
construct it zips your Dockerfile+app, uploads it to S3, creates least-privilege build and
VM-execution roles, resolves the managed base-image version, and emits a snapshotted MicroVM
image — with secure defaults and an overrides escape hatch for anything not yet modeled.
Running a MicroVM (run / suspend / resume / terminate) is a runtime API call, not CloudFormation — so it's driven with boto3 from your app or the E2E fixture, using the construct's typed properties (image ARN, execution role, connector ARNs, log group). No launcher Lambda / API Gateway / WAF in the current scope (a thin launcher is a deferred, opt-in add-on).
Two planes
flowchart LR
subgraph CFN["Declarative — CloudFormation (this construct)"]
IMG["AWS::Lambda::MicrovmImage<br/>(LambdaMicroVM)"]
NC["AWS::Lambda::NetworkConnector<br/>(VPC egress — Phase 3)"]
end
subgraph RT["Runtime API — boto3 (your app / E2E fixture)"]
RUN["RunMicrovm · Suspend · Resume · Terminate<br/>CreateMicrovmAuthToken"]
end
IMG -- "image ARN + exec role<br/>+ connector ARNs (props)" --> RUN
Images and connectors are declarative CDK; the running instance is runtime-only, wired from the construct's outputs.
Quickstart
from aws_cdk import Stack
from lambda_microvm_cdk import LambdaMicroVM
class MyStack(Stack):
def __init__(self, scope, id, **kw):
super().__init__(scope, id, **kw)
vm = LambdaMicroVM(self, "Agent",
source="microvm_app", # dir with a Dockerfile (also: .zip path or s3_assets.Asset)
description="headless agent VM",
memory_mib=2048, # tier: 512|1024|2048|4096|8192
environment={"LOG_LEVEL": "info"}, # NEVER secrets — baked into the snapshot
# architecture defaults to ARM_64 (only value the service accepts today)
# enable_logging=True, os_capabilities=[], overrides={} ...
)
vm.image_arn # Fn::GetAtt ImageArn (token)
vm.execution_role # least-priv VM execution role (add workload perms on top)
vm.grant_run(caller) # attach least-priv RunMicrovm* to a runtime-caller principal
Build & run flow
sequenceDiagram
participant Dev
participant CDK as CDK / CloudFormation
participant Svc as Lambda MicroVM service
participant App as your app / E2E fixture (boto3)
Dev->>CDK: cdk deploy (LambdaMicroVM)
CDK->>Svc: create MicrovmImage (S3 artifact + base image)
Svc-->>CDK: image CREATING -> CREATED (snapshot)
App->>Svc: RunMicrovm(imageArn, executionRoleArn, connectors, maxDuration)
Svc-->>App: microvmId, endpoint (PENDING -> RUNNING)
App->>Svc: CreateMicrovmAuthToken(allowedPorts=[8080])
App->>App: HTTPS request (X-aws-proxy-auth) -> assert
App->>Svc: TerminateMicrovm (guaranteed in teardown)
Sample app
sample/ is a deployable CDK app whose MicroVM runs a model worker on Amazon Bedrock
(us-east-1) — Amazon Nova 2 Lite by default (boto3 Converse), with Claude Opus 4.8 opt-in
(MODEL_PROVIDER=anthropic). The worker is tiered so the library's tests never depend on the model:
echo— deterministic, no model. This is what E2E asserts on.bedrock— one model call (Nova default / Opus opt-in).agent— Claude Code headless (opt-in enhancement, not required by the sample).
Getting started
Uses uv, ruff, and the AWS CDK CLI via
npx (see the Makefile).
make dev # uv sync (venv + dev deps)
make lint # ruff format --check + ruff check + mypy
make unit # unit tests (no AWS; boto3 mocked)
make synth # npx aws-cdk synth the sample app (runs cdk-nag)
CI/CD and the docs pipeline are described in docs/pipeline.md.
Code contributions
Contributions are welcome — please open an issue or PR. PR titles follow the
feature | fix | docs | chore convention (validated in CI).
Connect
- Website: www.ranthebuilder.cloud
- Blog: ranthebuilder.cloud/blog
- X (Twitter): @RanBuilder
- Email: ran.isenberg@ranthebuilder.cloud
License
This library is licensed under the MIT-0 License. See the LICENSE file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lambda_microvm_cdk-0.0.1.tar.gz.
File metadata
- Download URL: lambda_microvm_cdk-0.0.1.tar.gz
- Upload date:
- Size: 2.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79c25537343d77d1e5fdb25d21c5de654d5e06d4051307bb8ae46f1749a18456
|
|
| MD5 |
8fdf88d9857dc3a856a7ead5ee64add1
|
|
| BLAKE2b-256 |
76500da9052dbc46c41817b2cb8a7a144e33635a026eb70d3ad68e557eefb78b
|
Provenance
The following attestation bundles were made for lambda_microvm_cdk-0.0.1.tar.gz:
Publisher:
release.yml on ran-isenberg/lambda-microvm-cdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lambda_microvm_cdk-0.0.1.tar.gz -
Subject digest:
79c25537343d77d1e5fdb25d21c5de654d5e06d4051307bb8ae46f1749a18456 - Sigstore transparency entry: 2159272250
- Sigstore integration time:
-
Permalink:
ran-isenberg/lambda-microvm-cdk-python@9ebb6be843e96bd288683c47616c65f97cc24a07 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/ran-isenberg
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9ebb6be843e96bd288683c47616c65f97cc24a07 -
Trigger Event:
push
-
Statement type:
File details
Details for the file lambda_microvm_cdk-0.0.1-py3-none-any.whl.
File metadata
- Download URL: lambda_microvm_cdk-0.0.1-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f21f8896c6cabc8ba9c3bba81916c8268b9cc224a5d3bd9404dbbc7c712b9599
|
|
| MD5 |
ada55ead76854287ccd3ff3371213b1a
|
|
| BLAKE2b-256 |
804b086c7e3d01a924aa0e028589b827d3b20083f0ea390a93ad3dc01bbf5ad2
|
Provenance
The following attestation bundles were made for lambda_microvm_cdk-0.0.1-py3-none-any.whl:
Publisher:
release.yml on ran-isenberg/lambda-microvm-cdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lambda_microvm_cdk-0.0.1-py3-none-any.whl -
Subject digest:
f21f8896c6cabc8ba9c3bba81916c8268b9cc224a5d3bd9404dbbc7c712b9599 - Sigstore transparency entry: 2159272338
- Sigstore integration time:
-
Permalink:
ran-isenberg/lambda-microvm-cdk-python@9ebb6be843e96bd288683c47616c65f97cc24a07 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/ran-isenberg
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9ebb6be843e96bd288683c47616c65f97cc24a07 -
Trigger Event:
push
-
Statement type: