Referencing local libraries from parent directory fails quietly
See original GitHub issueDescription:
Prior to using SAM, it was common for me to import “internal libraries” into my lambda package by referencing them in the requirements file:
/project
/shared_lib
/<code>
/setup.py
/lambda_1
/<code>
/requirements.txt <- this will contain "../shared_lib"
When I run pip install -r lambda_1/requirements.txt -t deployment_package
this will add shared_lib to the deployment_package.
It seems in sam, this is wholly unsupported. When I run sam build
, it runs successfully, but the deployment package doesn’t actually contain the shared_lib (so it fails at runtime). It appears that sam is using pip download
instead of pip install
, which includes the dependencies from shared_lib/setup.py, but not shared_lib itself.
Tangentially: This fails when trying to run in a container (sam build -c), but I care a lot less because at least it fails at build time.
I have a workaround for this where I reference local packages using layers, but it seems pretty awful that this “works” until runtime.
Steps to reproduce the issue:
- Setup a library at the same level as your SAM lambda (ie. clone somepackage)
- Add the library reference to your SAM lambda requirements.txt (
../somepackage
) - Run sam build
Observed result:
- .aws-sam/build/<yourLambdaFunction>/ does not contain
somepackage
Expected result:
- .aws-sam/build/<yourLambdaFunction>/ contains
somepackage
- OR this fails
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Hi @jyoungs , It seems layer is the solution you are looking for. You can package the shared_lib into a zip file and use it. To use layer with SAM CLI, please find this document: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-layers.html This issue is more like a SAM CLI issue. I will transfer it to the related repository if you don’t mind: https://github.com/aws/aws-sam-cli.
Resolving this issue since SAM CLI already includes the Lambda Builders with following PR https://github.com/aws/aws-lambda-builders/pull/250