Specifying --template-file does not upload Python dependencies
See original GitHub issueDescription:
When specifying the template file with --template-file
with the sam package
command, my python dependencies are not included in my zip that gets uploaded to s3, subsequently is not importable in my lambda function.
My zip when I allow the template file to be defaulted is 7.2MB but when specified is 17KB. It only includes my Flask application code but no dependencies. It is even viewable in the online code editing window of Lambda.
Steps to reproduce the issue:
- Create another template say
dev-template.yaml
- Run
sam package --template-file dev-template.yaml --output-template-file packaged.yaml --s3-bucket S3_BUCKET_NAME
Observed result:
View in s3 that artifact is not the same size or that lambda is unable to run. In this case, I have api gateway and it returns an internal server error. Along with that, I’ve rm -rf .aws-sam
and run sam build - dev-template.yaml
prior and observed the same result. Even after nuking the .aws-sam, all my dependencies are built locally but not packaged.
Expected result: The .aws-sam/build/lambda-function-name folder would get fully uploaded, similar to when template file is not specified and run with default values.
Sam Version: 0.17.0 Python Version: 3.7.3
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:14 (2 by maintainers)
I got bitten by this today.
I think it means that with no
template
parameter it uses the (generated, processed) template file from the.aws-sam/build
directory, which references the code correctly. If you do pass this parameter it’s extremely unclear how it is supposed to work.One would think that doing
sam build --template somefile.yaml
thensam deploy --template-file somefile.yaml
would work, but it doesn’t.That’s pretty surprising behaviour! Also it’s not at all clear how one would actually get a second template file to work? Is the idea you do the build with it, and then update the references within it to point to the built code?
I too lost a couple hours wrestling with this. Resolved this using @keplerk 's approach in my Makefile:
It now builds and uploads all dependencies each time I run
make deploy
.