Deploying from Your Local Machine

This page shows you how to deploy a Cloud Function from your local machine using the gcloud command-line tool. When using the command-line tool, Cloud Functions packages and uploads the contents of your function's directory to a Cloud Storage bucket for you and automatically excludes unnecessary files via the .gcloudignore file.

Alternatively, you can use the Cloud Functions interface in the GCP Console to upload a ZIP file you make yourself.

For a complete runnable example that includes downloadable sample code, see the Using the gcloud Command-Line Tool quickstart.

Deploy using the gcloud tool

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

gcloud functions deploy NAME --runtime RUNTIME TRIGGER [FLAGS...]
Argument Description
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 flag, your code must contain a function with the same name.
--runtime RUNTIME The name of the runtime you are using, such as nodejs6, nodejs8, or python37.
TRIGGER The trigger type for this function (see Events and Triggers).
FLAGS... (Optional) Additional flags you can specify during deployment, such as --stage-bucket or --entry-point. For a full reference, see the gcloud functions deploy documentation.

Example

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

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

See the arguments in this command:

Argument Description
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 python37 The runtime for this function, in this case python37.
--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 functions deploy hello --entry-point helloworld --runtime python37 --trigger-http

Take a look at the arguments in this command:

Argument Description
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 in the source file.
--runtime python37 The runtime for this function, in this case python37.
--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