Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

fix(lambda): Docker executor mounts provided-runtime code at wrong path (#232)

Jay Janssena395b894975f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b1864313..ff544114 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,13 @@ Versioning follows [Semantic Versioning](https://semver.org/).
---
+## [Unreleased]
+
+### Fixed
+- **Lambda Docker executor fails for `provided` runtimes** — `_execute_function_docker()` mounted Lambda code only at `/var/task` and overrode CMD to `["/var/task/bootstrap"]`, but the AWS RIE entrypoint (`/lambda-entrypoint.sh`) in `public.ecr.aws/lambda/provided:al2023` expects the bootstrap binary at `/var/runtime/bootstrap`. Now mounts code at both `/var/task` and `/var/runtime` (matching real AWS layout) and passes `"bootstrap"` as CMD so the RIE finds the handler correctly. Contributed by @jayjanssen.
+
+---
+
## [1.1.61] — 2026-04-10
### Fixed
diff --git a/ministack/services/lambda_svc.py b/ministack/services/lambda_svc.py
index f9fcd7fe..2ad93f7f 100644
--- a/ministack/services/lambda_svc.py
+++ b/ministack/services/lambda_svc.py
@@ -1076,10 +1076,8 @@ def _execute_function_docker(func: dict, event: dict) -> dict:
# Build volume mounts
volumes: dict = {}
- if LAMBDA_DOCKER_VOLUME_MOUNT:
- volumes[LAMBDA_DOCKER_VOLUME_MOUNT] = {"bind": "/var/task", "mode": "ro"}
- else:
- volumes[code_dir] = {"bind": "/var/task", "mode": "ro"}
+ host_code_dir = LAMBDA_DOCKER_VOLUME_MOUNT or code_dir
+ volumes[host_code_dir] = {"bind": "/var/task", "mode": "ro"}
container_layer_dirs: list[str] = []
for idx, ld in enumerate(layers_dirs):
@@ -1123,19 +1121,23 @@ def _execute_function_docker(func: dict, event: dict) -> dict:
if is_provided:
# provided runtimes: use AWS Lambda RIE built into the provided image.
- # Make bootstrap executable, start container with RIE, POST event via HTTP.
- bootstrap_path = os.path.join(code_dir, "bootstrap")
- if os.path.exists(bootstrap_path):
- os.chmod(bootstrap_path, 0o755)
- # provided runtimes use the AWS Lambda RIE built into the base image.
- # RIE listens on port 8080; we POST the event and read the response.
+ # The RIE entrypoint runs /var/runtime/bootstrap, while user
+ # code is expected at /var/task. Mount the code dir to both
+ # paths using docker.types.Mount (the volumes dict can't bind
+ # the same host path to two container paths).
import urllib.request
bootstrap_path = os.path.join(code_dir, "bootstrap")
if os.path.exists(bootstrap_path):
os.chmod(bootstrap_path, 0o755)
+ mounts = [
+ docker_lib.types.Mount("/var/task", host_code_dir, type="bind", read_only=True),
+ docker_lib.types.Mount("/var/runtime", host_code_dir, type="bind", read_only=True),
+ ]
+ for idx, ld in enumerate(layers_dirs):
+ mounts.append(docker_lib.types.Mount(f"/opt/layer_{idx}", ld, type="bind", read_only=True))
run_kwargs: dict = {
- "image": image, "command": ["/var/task/bootstrap"],
- "environment": container_env, "volumes": volumes,
+ "image": image, "command": ["bootstrap"],
+ "environment": container_env, "mounts": mounts,
"ports": {"8080/tcp": None}, "detach": True, "stdin_open": False,
}
if LAMBDA_DOCKER_NETWORK:
diff --git a/tests/test_lambda.py b/tests/test_lambda.py
index b56475b8..f9428bf3 100644
--- a/tests/test_lambda.py
+++ b/tests/test_lambda.py
@@ -1350,3 +1350,52 @@ def test_lambda_provided_runtime_create(lam):
assert desc["Runtime"] == "provided.al2023"
assert desc["Handler"] == "bootstrap"
lam.delete_function(FunctionName="provided-test-v39")
+
+
+ os.environ.get("LAMBDA_EXECUTOR", "").lower() != "docker",
+ reason="requires LAMBDA_EXECUTOR=docker and Docker daemon",
+)
+def test_lambda_provided_runtime_docker_invoke(lam):
+ """Invoke a provided.al2023 Lambda via the Docker executor.
+
+ Uses a shell-script bootstrap that implements the Lambda Runtime API
+ (GET /invocation/next, POST /invocation/{id}/response).
+ """
+ # Shell bootstrap implementing the Lambda Runtime API protocol.
+ # Must loop: the RIE expects the bootstrap to poll for invocations.
+ bootstrap_script = (
+ "#!/bin/sh\n"
+ 'RUNTIME_API="${AWS_LAMBDA_RUNTIME_API}"\n'
+ "while true; do\n"
+ ' RESP=$(curl -s -D /tmp/headers '
+ '"http://${RUNTIME_API}/2018-06-01/runtime/invocation/next")\n'
+ ' REQUEST_ID=$(grep -i "Lambda-Runtime-Aws-Request-Id" /tmp/headers '
+ '| tr -d "\\r" | cut -d" " -f2)\n'
+ ' curl -s -X POST '
+ '"http://${RUNTIME_API}/2018-06-01/runtime/invocation/${REQUEST_ID}/response" '
+ "-d '{\"statusCode\":200,\"body\":\"hello from provided\"}'\n"
+ "done\n"
+ )
+ buf = io.BytesIO()
+ with zipfile.ZipFile(buf, "w") as zf:
+ info = zipfile.ZipInfo("bootstrap")
+ info.external_attr = 0o755 << 16 # executable
+ zf.writestr(info, bootstrap_script)
+
+ func_name = f"provided-docker-test-{_uuid_mod.uuid4().hex[:8]}"
+ lam.create_function(
+ FunctionName=func_name,
+ Runtime="provided.al2023",
+ Handler="bootstrap",
+ Code={"ZipFile": buf.getvalue()},
+ Role="arn:aws:iam::000000000000:role/test",
+ Timeout=30,
+ )
+ try:
+ resp = lam.invoke(FunctionName=func_name, Payload=json.dumps({"key": "value"}))
+ payload = json.loads(resp["Payload"].read())
+ assert payload["statusCode"] == 200
+ assert payload["body"] == "hello from provided"
+ finally:
+ lam.delete_function(FunctionName=func_name)