Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud Functions - Why are two positional arguments passed into my function by GCF?

I have a Google Cloud Function on Python 3.7 that does not take any input arguments. When I try to run it, it gives the following error:

TypeError: google_cloud_function() takes 0 positional arguments but 2 were given

The actual function code looks something like this (with different bash functions called):

import subprocess

def google_cloud_function():
    subprocess.call(["ls"], shell=True)
    subprocess.call(["pwd"], shell=True)

Why would this be the case?

like image 943
Balkan Avatar asked Oct 05 '18 01:10

Balkan


People also ask

Why does cloud deployment fail?

Cloud Functions deployment can fail if the entry point to your code, that is, the exported function name, is not specified correctly. Your source code must contain an entry point function that has been correctly specified in your deployment, either via Cloud console or Cloud SDK.

What is cold start in cloud functions?

But as we continue to expand the capabilities of Cloud Functions, the number-one friction point of FaaS is the “startup tax,” a.k.a. cold starts: if your function has been scaled down to zero, it can take a few seconds for it to initialize and start serving requests.


1 Answers

A background Cloud Function triggered by something like Cloud Storage should have the following function signature:

def function(data, context):
    ...

The arguments need to be included even if you aren't using them.

like image 125
Dustin Ingram Avatar answered Oct 27 '22 09:10

Dustin Ingram