Closed gbanister closed 2 years ago
I made this easier to reproduce.
See this repo: https://github.com/gbanister/HelloLambda/tree/master/HelloLambda
sam deploy
will package and publish the correct files.
sam deploy -t template.yaml
will package the entire project folder
I've also observed the sam package command also packages the entire project folder rather than the build products from the publish folder:
sam package --template-file template.yaml --output-template-file packaged.yaml --s3-bucket hello-lambda-package
I figured out how to do what I needed to do.
I have multiple environments defined in my samconfig.tomi and I have a template yaml file for each environment.
To build, package, and deploy to the non-default environments, it works if I use these commands:
sam build -t template-develop.yaml --config-env develop
sam package -t ./.aws-sam/build/template.yaml --output-template-file packaged.yaml --s3-bucket sam-packages-develop
sam deploy -t packaged.yaml --stack-name My-Lambda-develop
if there happens to be an easier way, let me know.
I was hit by this too, and it took me a while to figure out. Using build/deploy worked as expected. However, if I used package/publish and then deployed from the SAR, it would throw errors about the deployment package being too big. Once I downloaded the packaged source from S3, I was able to see that my entire git repo had been uploaded, including all the metadata in the .git/
directory.
The behavior I expected was for sam package
to use the artifacts from sam build
.
Edit: Like @gbanister noted above, I was also able to resolve this issue by telling sam package
to use the template from .aws-sam/build/template.yaml
instead of template.yaml
in the repo root.
sam deploy
and sam package
commands use the template in .aws-sam/build/template.yaml
by default. The relative paths of the local resources are resolved in the new template.
If the --template
is specified for these command, the local resources that it points to is not built. In this case, the whole project will be published. To resolve this, we suggest to run sam build
with --template
to specify the template you want to build, and then run sam deploy
or sam package
without --template
option
Please see the notes of --template
options in these documents:
Closing because it has been inactive for 2 weeks. Feel free to reopen it if you have any other questions.
Description:
My C# Lambda function is deployed (sam deploy) correctly without specifying template_file parameter. But, if I include the template_file, the package that gets deployed is the entire project directory, rather than just the publish directory which is at the path
src\projectname\bin\Release\.netcoreapp3.1\publish
.My samconfig.toml with the template_file parameter looks like this:
I see the same behavior if I use the -t parameter rather than specifying the template_file in the samconfig.toml
sam validate -t template.yaml
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
sam --version
: 1.15.0Add --debug flag to command you are running
Debug output