Stay organized with collections
Save and categorize content based on your preferences.
Deploy a function
This guide shows you how to deploy a function from source code using the
gcloud functions command. To learn how to deploy a function using the
gcloud run command, see
Deploy a Cloud Run function using the gcloud CLI.
The deployment process takes your source code and configuration settings and
builds a runnable image that Cloud Run functions
manages automatically in order to handle requests to your function.
At the bottom of the Google Cloud console, a
Cloud Shell
session starts and displays a command-line prompt. Cloud Shell is a shell environment
with the Google Cloud CLI
already installed and with values already set for
your current project. It can take a few seconds for the session to initialize.
The first argument, YOUR_FUNCTION_NAME, is a name for
your deployed function. The function name must start with a letter
followed by up to 62 letters, numbers, hyphens, or underscores, and must end
with a letter or a number. The name of the Cloud Run service that
is created for your function will replace underscores with hyphens and
uppercase letters will be converted to lowercase. For example,
Function_1 will be given the name function-1 in Cloud Run.
The --region flag
specifies the region in which to deploy your function. See
Locations for a list of regions supported by
Cloud Run.
The --runtime flag
specifies which language runtime your function uses. See
Runtime support for a list of supported
runtime IDs.
The --source flag
specifies the location of your function source code.
The --entry-point
flag specifies the entry point to your function in your source code. This is
the code that will be executed when your function runs. The value of this
flag must be a function name or fully-qualified class name that exists in
your source code. For more information, see
Function entry point.
To specify the trigger for your
function, additional flags (represented as
TRIGGER_FLAGS above) are required, depending on
the trigger you want to use:
Trigger the function with Eventarc when an
event that matches the specified filters occurs.
For a complete reference on the deployment command and its flags, see the
gcloud functions deploy
documentation.
For more details about gcloud functions deploy configuration flags,
refer to Cloud Run documentation.
When deployment finishes successfully, functions appear with a green check
mark in the Cloud Run overview page in the
Google Cloud console.
The initial deployment of a function may take several minutes, while the
underlying infrastructure is provisioned. Redeploying an existing function
is faster, and incoming traffic is automatically migrated to the newest version.
HTTP endpoint URL
When you create a function with the gcloud functions command or the
Cloud Functions v2 API, by default, the function has a
cloudfunctions.net HTTP endpoint URL. If you take this function and deploy it
on Cloud Run, your function also receives a run.app HTTP endpoint
URL. However, functions created in Cloud Run won't have an
cloudfunctions.net HTTP endpoint URL. A function's cloudfunctions.net URL
and run.app URL behave in exactly the same way. They are interchangeable,
and are used to trigger your function.
Functions created using the Cloud Functions v2 API
(for example, by using gcloud functions, the REST API, or Terraform) can be
managed with the Cloud Run Admin API
as well as the Cloud Functions v2 API.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003eThis guide outlines how to deploy a Cloud Run function from source code, which involves building a runnable image automatically managed by Cloud Run to handle requests.\u003c/p\u003e\n"],["\u003cp\u003eDeployment requires the Cloud Functions Developer IAM role or equivalent permissions and can be initiated using the \u003ccode\u003egcloud functions deploy\u003c/code\u003e command in Cloud Shell, specifying details like function name, region, runtime, source location, and entry point.\u003c/p\u003e\n"],["\u003cp\u003eFunctions can be triggered by HTTP requests, Pub/Sub messages, Cloud Storage events, or Eventarc events, each requiring specific trigger flags in the deployment command.\u003c/p\u003e\n"],["\u003cp\u003eSource code for deployment can be located on your local machine or in a Cloud Storage bucket, with the latter requiring the Cloud Run functions service agent to have \u003ccode\u003estorage.objects.get\u003c/code\u003e permission.\u003c/p\u003e\n"],["\u003cp\u003eThe initial deployment of a function can take several minutes, while redeployments are faster, and the deployment process also includes excluding unnecessary files through the \u003ccode\u003e.gcloudignore\u003c/code\u003e file.\u003c/p\u003e\n"]]],[],null,["# Deploy a function\n=================\n\nThis guide shows you how to deploy a function from source code using the\n`gcloud functions` command. To learn how to deploy a function using the\n`gcloud run` command, see\n[Deploy a Cloud Run function using the gcloud CLI](/run/docs/quickstarts/functions/deploy-functions-gcloud).\n\nThe deployment process takes your source code and configuration settings and\n[builds a runnable image](/functions/docs/building) that Cloud Run functions\nmanages automatically in order to handle requests to your function.\n\nDeployment basics\n-----------------\n\nFor an introduction on the type of functions you can deploy, see\n[Write Cloud Run functions](/run/docs/write-functions).\n\nUsers deploying functions must have the\n[Cloud Functions Developer](/functions/docs/reference/iam/roles#cloudfunctions.developer)\nIAM role or a role that includes the same permissions. See also\n[Additional configuration for deployment](/functions/docs/reference/iam/roles#additional-configuration).\n\n1. In the Google Cloud console, activate Cloud Shell.\n\n [Activate Cloud Shell](https://console.cloud.google.com/?cloudshell=true)\n\n\n At the bottom of the Google Cloud console, a\n [Cloud Shell](/shell/docs/how-cloud-shell-works)\n session starts and displays a command-line prompt. Cloud Shell is a shell environment\n with the Google Cloud CLI\n already installed and with values already set for\n your current project. It can take a few seconds for the session to initialize.\n2. Use the [`gcloud functions deploy`](/sdk/gcloud/reference/functions/deploy)\n command to deploy a function:\n\n ```sh\n gcloud functions deploy YOUR_FUNCTION_NAME \\\n --region=YOUR_REGION \\\n --runtime=YOUR_RUNTIME \\\n --source=YOUR_SOURCE_LOCATION \\\n --entry-point=YOUR_CODE_ENTRYPOINT \\\n TRIGGER_FLAGS\n ```\n\n The first argument, \u003cvar translate=\"no\"\u003eYOUR_FUNCTION_NAME\u003c/var\u003e, is a name for\n your deployed function. The function name must start with a letter\n followed by up to 62 letters, numbers, hyphens, or underscores, and must end\n with a letter or a number. The name of the Cloud Run service that\n is created for your function will replace underscores with hyphens and\n uppercase letters will be converted to lowercase. For example,\n `Function_1` will be given the name `function-1` in Cloud Run.\n | **Note:** Run `gcloud config set functions/gen2 true` to set all future first time deployments.\n - The [`--region`](/sdk/gcloud/reference/functions/deploy#--region) flag\n specifies the region in which to deploy your function. See\n [Locations](/run/docs/locations) for a list of regions supported by\n Cloud Run.\n\n - The [`--runtime`](/sdk/gcloud/reference/functions/deploy#--runtime) flag\n specifies which language runtime your function uses. See\n [Runtime support](/functions/docs/runtime-support) for a list of supported\n runtime IDs.\n\n - The [`--source`](/sdk/gcloud/reference/functions/deploy#--source) flag\n specifies the location of your function source code.\n\n - The [`--entry-point`](/sdk/gcloud/reference/functions/deploy#--entry-point)\n flag specifies the entry point to your function in your source code. This is\n the code that will be executed when your function runs. The value of this\n flag must be a function name or fully-qualified class name that exists in\n your source code. For more information, see\n [Function entry point](/run/docs/write-functions#function_entry_point).\n\n - To specify the [trigger](/sdk/gcloud/reference/functions/deploy#--trigger-bucket) for your\n function, additional flags (represented as\n \u003cvar translate=\"no\"\u003eTRIGGER_FLAGS\u003c/var\u003e above) are required, depending on\n the trigger you want to use:\n\n For a complete reference on the deployment command and its flags, see the\n [`gcloud functions deploy`](/sdk/gcloud/reference/functions/deploy)\n documentation.\n\n For more details about `gcloud functions deploy` configuration flags,\n refer to [Cloud Run documentation](/run/docs/configuring).\n\nWhen deployment finishes successfully, functions appear with a green check\nmark in the Cloud Run overview page in the\n[Google Cloud console](https://console.cloud.google.com/run).\n\nThe initial deployment of a function may take several minutes, while the\nunderlying infrastructure is provisioned. Redeploying an existing function\nis faster, and incoming traffic is automatically migrated to the newest version.\n| **Note:** Instances provisioned with a previous version of a function may continue running and processing traffic for several minutes after a new deployment has finished. This ensures that traffic sent to your function while a deployment is in progress isn't dropped. Also note that when a deployment fails, if there is a previous version of the function, it will continue to be available in most cases.\n\nHTTP endpoint URL\n-----------------\n\nWhen you create a function with the `gcloud functions` command or the\nCloud Functions v2 API, by default, the function has a\n`cloudfunctions.net` HTTP endpoint URL. If you take this function and deploy it\non Cloud Run, your function also receives a `run.app` HTTP endpoint\nURL. However, functions created in Cloud Run won't have an\n`cloudfunctions.net` HTTP endpoint URL. A function's `cloudfunctions.net` URL\nand `run.app` URL behave in exactly the same way. They are interchangeable,\nand are used to trigger your function.\n\nTerraform examples\n------------------\n\nFor examples about how to deploy functions using Terraform, see the\n[Terraform HTTP example](/functions/docs/tutorials/terraform) and\n[Terraform Pub/Sub example](/functions/docs/tutorials/terraform-pubsub).\n\nConfigure networking\n--------------------\n\nFunctions created using the [Cloud Functions v2 API](/functions/docs/apis)\n(for example, by using `gcloud functions`, the REST API, or Terraform) can be\nmanaged with the [Cloud Run Admin API](/run/docs/reference/cloud-run-admin-api-overview)\nas well as the Cloud Functions v2 API.\n| **Note:** If you created a Cloud Run function using `gcloud run` commands or the Cloud Run Admin API, you can't manage that function with `gcloud functions` commands or the Cloud Functions v2 API.\n\nTo learn more about managing networks for functions, including how to route\n[VPC network traffic](/run/docs/configuring/connecting-vpc), see\n[Best practices for Cloud Run networking](/run/docs/configuring/networking-best-practices).\n\nLearn how to deploy Cloud Run functions on Cloud Run\n----------------------------------------------------\n\nDeploying functions on Cloud Run is similar to the steps described in\nthis document, but with some added advantages:\n\n- You can use the Google Cloud console, as well as the gcloud CLI (`gcloud run deploy`).\n- The steps for specifying triggers are slightly different. To learn more, see [triggers and retries](/run/docs/functions/comparison#triggers_and_retries) and [examples of function triggers](/run/docs/function-triggers#triggers).\n- Cloud Run offers a broader array of configuration options:\n - [Minimum instances](/run/docs/configuring/min-instances)\n - [Concurrency](/run/docs/configuring/concurrency)\n - [Container configuration](/run/docs/configuring/services/containers)\n - [CPU limits](/run/docs/configuring/services/cpu)\n - [Memory limits](/run/docs/configuring/services/memory-limits)\n - [Request timeout](/run/docs/configuring/request-timeout)\n - [Secrets](/run/docs/configuring/services/secrets)\n - [Environment variables](/run/docs/configuring/services/environment-variables)\n - [Execution environment](/run/docs/configuring/execution-environments)\n - [HTTP/2](/run/docs/configuring/http2)\n - [Service accounts](/run/docs/configuring/services/service-identity)\n - [Cloud SQL connections](/run/docs/configuring/connect-cloudsql)\n - [Session affinity and traffic splitting](/run/docs/configuring/session-affinity#affinity-and-traffic-splitting)\n - [Tags](/run/docs/configuring/tags)\n - [Networking](/run/docs/configuring/networking-best-practices)"]]