sam build includes absolute paths in Golang binaries
See original GitHub issueDescription:
When you run sam build
and sam package
in two instances of the same projects with different absolute paths and upload to the same S3 bucket, the compiled binaries will be uploaded both times, even though the binaries are identical.
According to #2110 this has been fixed, but I can still reproduce the issue on Windows.
Steps to reproduce:
- Clone this repository into a directory on your local Windows machine.
cd
into the directory.- Run
sam build
. - Run
sam package --s3-bucket YOUR_BUCKETNAME
- Clone the same repository into a second directory on your local windows machine.
- Copy the second directory into a third directory using
xcopy seconddirectory thirddirectory /s /e
. cd
into the second directory.- Run
sam build
. - Run
sam package --s3-bucket YOUR_BUCKETNAME
cd
into the third directory.- Run
sam build
. - Run
sam package --s3-bucket YOUR_BUCKETNAME
Observed result:
The calculated hashes change, when the parent directory changes. This results in the compiled binaries being re-uploaded for every directory, although no files have been modified.
Expected result:
Hashes should not depend on the parent directory. Compiled binaries should only be uploaded, when they have been modified.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: Windows 10 Pro Version 20H2 (Build 19042.1165)
sam --version
: 1.31.0- AWS region: eu-central-1
Further notes:
I can imagine this is also the cause for the issue #2872, where running sam package
in an ephemeral container results in the files being uploaded every time.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (3 by maintainers)
@sriram-mv I have opened a pull request in aws-lambda-builders allowing this option to be passed in.
Once this PR is reviewed and merged I believe this project can be updated here to something along the lines of:
I believe this will allow SAM template users to define functions like the following:
Which fixes the issue described above by @suroh1994 and @jaglade
@jaglade This will be a welcome contribution to the
aws-lambda-builders
golang build workflow and we can make this feature opt-in (atleast at this point, I have not considered the ramifications of the change in behavior causing breaks).