Open git-noise opened 2 months ago
Hey @git-noise thanks for raising the issue. After some digging, it seems the limitation is that, in the docker-in-docker scenario, the path (/tmp/tmpqn5dh6cm
in your example) mounted to /var/task
is relative to the host but not to the container. /tmp/tmpqn5dh6cm
does not exist in the host but only in the container. That's why /var/task
is empty. (reference: https://forums.docker.com/t/mounting-a-volume-not-working-with-running-docker-in-docker/25775/3)
SAM CLI does not support "Docker-in-Docker" right now. I'll mark this issue as a feature request for support for "Docker-in-Docker" and bring that up to the team.
Hello, thanks a lot for looking into it @hawflau.
Based on your insight, I was able to confirm that it is indeed an issue relating to volume mounting.
A quick test check that consists in mounting the full /tmp in the docker container, ensures that the temporary directory - here /tmp/tmpqn5dh6cm
- is available within both the host and the container, and then /var/task
properly populated.
Maybe an "easy" fix would be to adjust the function that creates these temporary directory, to take an optional base directory parameter? It would then allow for these temporary directory to be still created on the host, but in a specific directory that could be mounted on the sam-cli container?
Thanks for your help,
@hawflau did this break recently? There are lots of posts and references for how to do docker-in-docker, including issues in this repo discussing how to get it working. I'm very surprised to see that it is not supported.
FWIW, I have the same exact issue (empty /var/task
)
Description:
When running
sam local start-api
in a docker-out-of-docker setup, it seems that the/var/task
folder mounted into the lambda-executing container is not populated with the zip containing the lambda binary.Steps to reproduce:
Create a simple JS hello-world, zip it and drop to a common path - here
/tmp/lambda-bins
Create a basic setup with an API Gateway and one lambda endpoint:
Create a simple docker container with the aws-sam-cli.
RUN apk add --no-cache --virtual build-deps build-base libffi-dev gcc \ && pip install --no-cache-dir aws-sam-cli==1.116.0 \ && pip3 uninstall --yes pip \ && apk del build-deps
networks: sam_subnet: driver: bridge name: test-sub
services: sam-lambda: build: . working_dir: /opt/data ports:
Docker
SAM template
Directory on the host with the lambda binaries
Observed result:
The lambda function fails to execute with the following:
As one can see, although the binary seems properly located as per this line:
sam-lambda-1 | 2024-05-06 17:41:11,715 | Decompressing /tmp/lambda-bins/lambda-hello-world.zip
It seems that
/var/task
ends up being empty in the lambda-executing container.Expected result:
We would expect the binary to be mounted into the lambda-executing container, and then the lambda function to properly execute.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
sam --version
: 1.116.0