Python-docs-samples: [Functions] Using zip upload as source code

Created on 26 Jul 2018  路  6Comments  路  Source: GoogleCloudPlatform/python-docs-samples

In which file did you encounter the issue?

Folder: https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/functions/helloworld

Did you change the file? If so, how?

No, possible problem in Cloud Functions beta Python 3.7

Describe the issue

zipped the folder specified above

In google console >> Cloud Functions >> Create function:

  • Trigger: http
  • source code: zip upload
  • Runtime: python 3.7
  • bucket:
  • function to execute: hello_get

Create

Then the following error happens (after creation completes):
Deployment failure: Function load error: File main.py that is expected to define function doesn't exist

Fixit

Most helpful comment

As I found out (sorry for not posting the solution before), to resolve this problem you have to zip the files directly, that is, select all the files and choose compact to zip, instead of the whole folder

This issue can be closed I suppose

All 6 comments

I'm having the same issue but with my own 'hello-world' type effort. My zip file contains 3 files, zip attached.

From the create function form in the Google Cloud Console I answered with the following values...
function name: foos
trigger: HTTP
source code:
zip upload
provided zip file containing above files
runtime:
python 3.7
function to execute:
foos

As I found out (sorry for not posting the solution before), to resolve this problem you have to zip the files directly, that is, select all the files and choose compact to zip, instead of the whole folder

This issue can be closed I suppose

I would contend that it shouldn't be closed. Forcing a developer to manually assemble the zip file an entry at a time is not tenable. We need to be able to use tools like the maven-assembly-plugin to assemble these zip files via an automated process.

What I want to know is what is WRONG with the zip file I assembled as opposed to one created by adding a file at a time using the Finder and compress on Mac OS X. Knowing that maybe I can go about the automated assembly in a different way.

I believe the reason for this is that the CloudFunction, under the hood, does not have a proper file system, so your zip can't contain any folder, only files; that is, files must be in the root zip, as the CloudFunction doesn't access other folders levels (all assumptions)

The samples in this repository are working provided the zip file contains only files, no folders. That's the intended behavior.

If you feel that the documentation on the web site should be changed, you can submit feedback directly from that web page.

As I found out (sorry for not posting the solution before), to resolve this problem you have to zip the files directly, that is, select all the files and choose compact to zip, instead of the whole folder

This issue can be closed I suppose

here is the documentation.
https://cloud.google.com/functions/docs/deploying/console

_Note: Make sure your source files are at the root of the ZIP file, rather than a folder containing the files._

Was this page helpful?
0 / 5 - 0 ratings