lambci /docker-lambda

Docker images and test runners that replicate the live AWS Lambda environment

★ 5,773⑂ 406👁 2⑃ 80● 288▤ 0
C#MITCreated 2016-05-26
+0
日增长
5,773
stars
406
forks
2
watchers
80
prs
288
issues
0
releases

README

Deprecated

NB: these images are deprecated in favor of AWS' official images, which you can find at:

https://github.com/aws/aws-lambda-base-images

And browse on the ECR public gallery, eg:

https://gallery.ecr.aws/lambda/python

This project is now archived and will not receive any further updates.

 docker-lambda

A sandboxed local environment that replicates the live AWS Lambda
environment almost identically – including installed software and libraries,
file structure and permissions, environment variables, context objects and
behaviors – even the user and running process are the same.



You can use it for running your functions in the same strict Lambda environment,
knowing that they'll exhibit the same behavior when deployed live. You can
also use it to compile native dependencies knowing that you're linking to the
same library versions that exist on AWS Lambda and then deploy using
the AWS CLI.

---

 Contents

 Usage
 Run Examples
 Build Examples
 Using a Dockerfile to build
 Docker tags
 Verifying images
 Environment variables
 Build environment
 Questions

---

 Usage

 Running Lambda functions

You can run your Lambdas from local directories using the -v arg with
docker run. You can run them in two modes: as a single execution, or as
an API server that listens for invoke events.
The default is single execution mode, which outputs all logging to stderr and the result of the handler to stdout.

You mount your (unzipped) lambda code at /var/task and any (unzipped) layer
code at /opt, and most runtimes take two arguments – the first for the
handler and the second for the event, ie:

sh
docker run --rm \
  -v :/var/task:ro,delegated \
  [-v :/opt:ro,delegated] \
  lambci/lambda: \
  [] []


(the --rm flag will remove the docker container once it has run, which is usually what you want,
and the ro,delegated options ensure the directories are mounted read-only and have the highest performance)

You can pass environment variables (eg -e AWS_ACCESS_KEY_ID=abcd) to talk to live AWS services,
or modify aspects of the runtime. See below for a list.

 Running in "stay-open" API mode

If you pass the environment variable DOCKER_LAMBDA_STAY_OPEN=1 to the container, then instead of
executing the event and shutting down, it will start an API server (on port 9001 by default), which
you can then call with HTTP following the Lambda Invoke API.
This allows you to make fast subsequent calls to your handler without paying the "cold start" penalty each time.

sh
docker run --rm [-d] \
  -e DOCKER_LAMBDA_STAY_OPEN=1 \
  -p 9001:9001 \
  -v :/var/task:ro,delegated \
  [-v :/opt:ro,delegated] \
  lambci/lambda: \
  []


(the -d flag will start the container in detached mode, in the background)

You should then see:

sh
Lambda API listening on port 9001...


Then, in another terminal shell/window you can invoke your function using the AWS CLI
(or any http client, like curl):

sh
aws lambda invoke --endpoint http://localhost:9001 --no-sign-request \
  --function-

Top issues

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON