question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Specifying --template-file does not upload Python dependencies

See original GitHub issue

Description:

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:

  1. Create another template say dev-template.yaml
  2. 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

11reactions
nlothiancommented, Apr 30, 2020

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 then sam 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?

2reactions
abk7777commented, Dec 7, 2021

I too lost a couple hours wrestling with this. Resolved this using @keplerk 's approach in my Makefile:

deploy: 
	@sam build \
		--template-file template.yaml && \
	sam package \
		--resolve-s3 \
		--output-template-file packaged.yaml && \
	sam deploy \
		--no-fail-on-empty-changeset \
		--region "${REGION}" \
		--template-file packaged.yaml \
		--stack-name "${STAGE}-${APP_NAME}-${SERVICE}" \
		--capabilities CAPABILITY_IAM \
		--parameter-overrides \
                    ...

It now builds and uploads all dependencies each time I run make deploy.

Read more comments on GitHub >

github_iconTop Results From Across the Web

template-file does not upload Python dependencies ... - GitHub
When specifying the template file with --template-file with the sam package command, my python dependencies are not included in my zip that gets ......
Read more >
AWS SAM CLI ignoring my Python dependencies during build ...
yml and uploads only the function code. So my solution was: specify --template-file in sam build; run sam deploy without --template-file option.
Read more >
templatefile - Functions - Configuration Language | Terraform
This function can be used only with files that already exist on disk at the beginning of a Terraform run. Functions do not...
Read more >
sam build - AWS Serverless Application Model
The sam build command processes your AWS SAM template file, application code, and any applicable language-specific files and dependencies. The command also ...
Read more >
Specifying dependencies in Python | Cloud Functions ...
Packaging local dependencies. You can also package and deploy dependencies alongside your function. This approach is useful if your dependency is not available ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found