Deploying from Your Local Machine

Local deployments work by uploading a ZIP file containing your function to a Google Cloud Storage Bucket, then including that bucket in the deploy command. When using the command-line tool, Cloud Functions zips up the contents of your functions directory for you. Alternatively, you can use the Cloud Functions interface in the Cloud Platform Console to upload a ZIP file you make yourself.

Create a Cloud Storage Bucket

First you'll need a Cloud Storage Bucket to act as the temporary staging area for your function code.

If you don't already have a Cloud Storage Bucket, follow these steps to create one:

  1. Open the Cloud Storage Console.
  2. Create a new bucket.
  3. Type the bucket name (we will use the name "cloud-functions" hereafter), then choose whichever storage class and location you prefer.
  4. Click Create.

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 beta functions deploy <NAME> --stage-bucket <BUCKET_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 export a function with the same name.
--stage-bucket <BUCKET_NAME> The name of the Cloud Storage bucket where your function source will be uploaded.
<TRIGGER> The trigger type for this function (see Calling Cloud Functions).
Optional Arguments
--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 exported in your source file has a different name than the <NAME> argument you're using to deploy.

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

gcloud beta functions deploy helloworld --stage-bucket cloud-functions --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 export a function named helloworld.
--stage-bucket cloud-functions The name of the Cloud Storage bucket where your function source will be uploaded, in this case cloud-functions.
--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 --stage-bucket cloud-functions --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 an exported function named helloworld.
--stage-bucket cloud-functions The name of the Cloud Storage bucket where your function source will be uploaded, in this case cloud-functions.
--trigger-http The trigger type for this function, in this case an HTTP request (webhook).

The --entry-point option is useful when the names of your exported functions do not meet the naming requirements for Cloud Functions.

Next steps

Send feedback about...

Cloud Functions Documentation