简体   繁体   中英

Google Cloud Functions: error deploying, main.py doesn't exist

Deploying Google Cloud Functions from the local system fails with the following error:

ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Function load error: File main.py that is expected to define function doesn't exist

I've used the console UI to check the contents of the package that was uploaded in the failed deployment and the file is present . The package was created using the gcloud CLI:

gcloud functions deploy <redacted> \
    --trigger-http \
    --runtime=python37 \
    --region=europe-west1 \
    --project=<redacted> \
    --entry-point=<redacted>

For context, the same project was deployed successfully multiple times by several people but started failing for everyone new that checked it out after a specific date.

In our case, this was because of invalid credentials, ie the JSON file passed to ServiceAccountCredentials.from_json_keyfile_name was missing. Confusingly, the error doesn't mention anything about security, credentials or that missing file.

Secrets are not in version control and the shared vault had a stale file that did not match the path provided in the python script. This was fixed once the credentials were corrected.

We managed to isolate the problem to the authenticated call by successfully deploying 'dumb' functions (return a string) and then incrementally adding back functionality until it broke.

I solved this problem in my application in Node.js, basically I identified that the .gcloudignore file it invokes the .gitignore of the project, so if your function is in a skipped folder it simply does not find, then just remove the line #! Include : .gitignore #! Include : .gitignore file .gcloudignore

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM