Deploying from Your Local Machine

Local deployments work by uploading a ZIP file containing your function to a Google Cloud Storage Bucket. When using the command-line tool, Cloud Functions zips up the contents of your functions directory for you and automatically excludes unnecessary files via .gcloudignore. Alternatively, you can use the Cloud Functions interface in the GCP Console to upload a ZIP file you make yourself.

Deploy using the gcloud tool

Using the gcloud command-line tool, deploy your function from the path containing your function code with the deploy command. The command has the following format:

gcloud functions deploy NAME TRIGGER

Let's look at the arguments in this command:

Argument Description
deploy The Cloud Functions command you are executing, in this case the deploy command.
NAME The name of the Cloud Function you are deploying. This name can only contain letters, numbers, underscores, and hyphens. Unless you specify the --entry-point option, your module must contain a function with the same name.
TRIGGER The trigger type for this function (see Calling Cloud Functions).
Optional Arguments
--stage-bucket STORAGE_BUCKET The Cloud Storage Bucket to store your function's code in. If this argument is omitted, Cloud Functions automatically generates a storage bucket to upload functions to.
--entry-point FUNCTION_NAME The name of a function that should be used as an entry point, instead of the NAME argument that is used by default. Use this optional argument when the function in your source file has a different name than the NAME argument you're using to deploy.

The following example deploys a function written in Python and assigns it an HTTP trigger:

gcloud beta functions deploy helloworld --runtime python37 --trigger-http

Let's look at the arguments in this command:

Argument Description
deploy The Cloud Functions command you are executing, in this case the deploy command.
helloworld The name of the Cloud Function you are deploying, in this case helloworld. The deployed Cloud Function will be registered under the name helloworld, and the source file must contain a function named helloworld.
--runtime The runtime for this function, in this case python37. You only use this flag for runtimes other than Node.js 6 (which is selected by default).
--trigger-http The trigger type for this function, in this case an HTTP request (webhook).

The following example deploys the same function but under a different name:

gcloud beta functions deploy hello --entry-point helloworld --runtime python37 --trigger-http

Let's look at the arguments in this command:

Argument Description
deploy The Cloud Functions command you are executing, in this case the deploy command.
hello The name of the Cloud Function you are deploying, in this case hello. The deployed Cloud Function will be registered under the name hello.
--entry-point helloworld The deployed Cloud Function will use a function named helloworld.
--runtime The runtime for this function, in this case python37. You only use this flag for runtimes other than Node.js 6 (which is selected by default).
--trigger-http The trigger type for this function, in this case an HTTP request (webhook).

The --entry-point option is useful when the functions in your source code do not meet the naming requirements for Cloud Functions.

Next steps

Was this page helpful? Let us know how we did:

Send feedback about...

Cloud Functions Documentation