Closed aleccarper closed 6 years ago
You should chmod and give your binary executable permissions
I'm also getting this on a Go project. My reproducible branch is at https://github.com/nzoschke/gofaas/pull/62
Turns out, this is a regression from previous version because Python's ZipFile module does not retain file permissions on unzipping - https://bugs.python.org/issue15795.
Several folks have fixed it in different ways (ex: https://www.burgundywall.com/post/preserving-file-perms-with-python-zipfile-module). We need to implement a clean solution to this problem.
We will prioritize this and get a release out asap
We did some digging in on the awsdevelopers Slack. With some sleep and debug statements I see that the tmp dir doesn't have any executable bits on the main file:
$ cd /var/folders/px/fd8j3qvn13gcxw9_nw25pphw0000gn/T/tmpKXhUgv
$ ls -al
total 36816
drwx------ 3 noah staff 102 May 9 07:45 .
drwx------@ 259 noah staff 8806 May 9 07:45 ..
-rw-r--r-- 1 noah staff 18846338 May 9 07:45 main
@sanathkr found this, which points to Python zip library:
looks like zipfile Python module doesn’t retain permissions on unzip.. - https://stackoverflow.com/questions/434641/how-do-i-set-permissions-attributes-on-a-file-in-a-zip-file-using-pythons-zip/6297838#6297838
This problems is specifically only when you bundle the Golang binary as a zipfile and provide to CodeUri. As a workaround, you can set CodeUri to be a path to a folder that contains your binary. This will work. In fact this will be faster because SAM CLI does not have to unzip every time you run the invoke.
If you have something like:
MyFunction:
Type: AWS::Serverless::Function
Properties:
...
CodeUri: ./myfunction.zip
Instead, convert it to something like:
MyFunction:
Type: AWS::Serverless::Function
Properties:
...
CodeUri: ./build
Where the build
folder contains your Golang binary. This will save you the step of building a zip file and also improve performance because SAM CLI doesn't have to unzip on every invoke.
This problems is specifically only when you bundle the Golang binary as a zipfile and provide to CodeUri.
I can confirm that this is an issue on Linux for a Python project (the issue is not limited to Golang on MacOS).
As a workaround, you can set CodeUri to be a path to a folder that contains your binary.
I just tested this, and it worked properly. Thanks!
Thanks all!
Reopening. The root cause of this is not fixed.
Description:
After upgrading to 0.3.0 I am now getting the following error while using
sam local start-api
I have tried rebuilding my functions using
but that doesn't seem to be fixing the issue.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc) Mac/OSX
Output of
sam --version
: SAM CLI, version 0.3.0Optional Debug logs: