sam build with --use container doesn't work if sam is running inside a container
See original GitHub issueI am trying to build my lambda package inside a container with latest aws-sam-cli installed. Consider a scenario with a Jenkins or any CI server running inside containers.
Here are the reproduction steps:
- Run a container in interactive mode with aws-sam-cli installed.
docker run -v /var/run/docker.sock:/var/run/docker.sock -ti --entrypoint bash samcli:latest
- Run sam Build command
sam build -u -t template.yml
- Expected: Sam build should be able to executed with
--use-container
option - Actual: Getting an error with
Requirements file not found: /tmp/samcli/source/requirements.txt
root@d2da5d926823:/# sam build -u -t aws.cfn.app.yml Starting Build inside a container Building codeuri: / runtime: python3.8 metadata: {} functions: [‘KafkaLagLambdaFn’] Fetching public.ecr.aws/sam/build-python3.8:latest Docker container image… Mounting / as /tmp/samcli/source:ro,delegated inside runtime container Build Failed Running PythonPipBuilder:ResolveDependencies Error: PythonPipBuilder:ResolveDependencies - Requirements file not found: /tmp/samcli/source/requirements.txt
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
sam build - AWS Serverless Application Model
Build an AWS SAM application using the sam build command from the AWS SAM CLI. ... build inside a Lambda-like Docker container $...
Read more >AWS SAM DockerBuildArgs It does not add them when ...
I am trying to test a lambda function locally, the function is created from the public docker image from aws, however I want...
Read more >Building applications - Amazon Serverless Application Model
Use the sam build command to build an Amazon SAM serverless application as a .zip file archive or a container image.
Read more >SAM & Docker Builds-- How do they update (not working for ...
When I go to the Dockerfile and the app.py to make changes and expand the text analysis functions I am trying to use,...
Read more >Let's Try Lambda Container Support with SAM CLI - hayao-k.dev
The AWS SAM CLI supports container images in v1.13.1. ... If you use your own base image, you can run tests by adding...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi all,
@aahung I got the same error with a nodejs Lambda :
As you said sam is not really to blame here, it’s a docker-in-docker catch : the sam container is trying to bind mount the working dir. But the mount path has to be correct from the host perspective, and chances are that’s not possible without doing nasty things (like recreating the docker volume driver path/filesystem in the container).
One nice thing would be able to add additional docker volumes to a sam container (should we add a feature request ?). That’s almost already implemented but not available in the SAM build CLI interface. The nice thing about named docker volumes are that they don’t suffer from the host path perspective “problem”.
Finally, what I recommend to fix this issue if you are running sam in a CI/CD container runner : don’t use your usual Docker image for your CI/CD container runner docker executor and directly use AWS SAM lambda container images (the images ran if you specify
--use-container
). For GitLab, that’s theimage
keyword. They already contains sam and other tools to build and manage dependency in your lambda runtime choice. Find those images here. That way, if your function depends on packages have natively compiled dependencies, they will be built in AWS Lambda-like Docker container, as--use-container
does. That way, you can remove this flag from your CI/CD script and now it works !This is also a problem when building functions that use container images (https://docs.aws.amazon.com/lambda/latest/dg/images-create.html).