lambci / docker-lambda

Docker images and test runners that replicate the live AWS Lambda environment
MIT License
5.83k stars 431 forks source link

Add file watching #231

Closed mhart closed 4 years ago

mhart commented 4 years ago

Addresses #229

Can either send SIGHUP to the bootstrap process:

docker kill --signal=SIGHUP <container_id>

Or, if you pass DOCKER_LAMBDA_WATCH=1 as an env var, then any changes to files in /var/task or /opt (ie, your handler directory and any layers you have mounted) will trigger the bootstrap to be killed (and it will cold start again on next invocation)

docker run --rm -v "$PWD":/var/task:ro,delegated \
  -e DOCKER_LAMBDA_STAY_OPEN=1 \
  -e DOCKER_LAMBDA_WATCH=1 \
  -p 9001:9001 \
  lambci/lambda:provided handler

Works with the following runtimes: provided, nodejs10.x, nodejs12.x, python3.7, python3.8 ruby2.5, java11

The other runtimes will need another strategy that restarts the root process (the easiest will be to utilize docker run --restart on-failure and then having the runtimes error if the bootstrap exits)