Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Funktion bereitstellen
In dieser Anleitung erfahren Sie, wie Sie eine Funktion aus dem Quellcode mit dem Befehl gcloud functions bereitstellen. Informationen zum Bereitstellen einer Funktion mit dem Befehl gcloud run finden Sie unter Cloud Run-Funktion mit der gcloud CLI bereitstellen.
Beim Bereitstellungsprozess werden die Quellcode- und Konfigurationseinstellungen verwendet und ein ausführbares Image erstellt, das von Cloud Run Functions automatisch verwaltet wird, um Anfragen an die Funktion zu verarbeiten.
Bereitstellungsgrundlagen
Eine Einführung in die Arten von Funktionen, die Sie bereitstellen können, finden Sie unter Cloud Run-Funktionen schreiben.
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.
Das erste Argument, YOUR_FUNCTION_NAME, ist ein Name für Ihre bereitgestellte Funktion. Der Name muss mit einem Buchstaben beginnen, gefolgt von bis zu 62 Buchstaben, Ziffern, Bindestrichen oder Unterstrichen. Das letzte Zeichen muss ein Buchstabe oder eine Ziffer sein. Im Namen des Cloud Run-Dienstes, der für Ihre Funktion erstellt wird, werden Unterstriche durch Bindestriche ersetzt und Großbuchstaben in Kleinbuchstaben umgewandelt. Function_1 erhält beispielsweise den Namen function-1 in Cloud Run.
Das Flag --region gibt die Region an, in der die Funktion bereitgestellt werden soll. Eine Liste der von Cloud Run unterstützten Regionen finden Sie unter Standorte.
Das Flag --runtime gibt an, welche Sprachlaufzeit die Funktion verwendet. Eine Liste der unterstützten Laufzeit-IDs finden Sie unter Laufzeitunterstützung.
Das Flag --source gibt den Speicherort des Quellcodes der Funktion an.
Das Flag --entry-point gibt den Einstiegspunkt für die Funktion in Ihrem Quellcode an. Dies ist der Code, der beim Ausführen der Funktion ausgeführt wird. Der Wert dieses Flags muss ein Funktionsname oder ein voll qualifizierter Klassenname sein, der in Ihrem Quellcode vorhanden ist. Weitere Informationen finden Sie unter Funktionseinstiegspunkt.
Zum Festlegen des Triggers für Ihre Funktion sind je nach gewünschtem Trigger zusätzliche Flags (TRIGGER_FLAGS oben dargestellt) erforderlich:
Lösen Sie die Funktion mit Eventarc aus, wenn ein Ereignis mit den angegebenen Filtern übereinstimmt.
Eine vollständige Referenz zum Bereitstellungsbefehl und seinen Flags finden Sie in der Dokumentation zu gcloud functions deploy.
Weitere Informationen zu gcloud functions deploy-Konfigurationsflags finden Sie in der Cloud Run-Dokumentation.
Wenn die Bereitstellung erfolgreich abgeschlossen wurde, werden Funktionen mit einem grünen Häkchen auf der Cloud Run-Übersichtsseite in der Google Cloud Console angezeigt.
Die anfängliche Bereitstellung einer Funktion kann einige Minuten dauern, während die zugrunde liegende Infrastruktur bereitgestellt wird. Die erneute Bereitstellung einer vorhandenen Funktion ist schneller und der eingehende Traffic wird automatisch zur neuesten Version migriert.
HTTP-Endpunkt-URL
Wenn Sie eine Funktion mit dem Befehl gcloud functions oder der Cloud Functions v2 API erstellen, hat die Funktion standardmäßig eine cloudfunctions.net-HTTP-Endpunkt-URL. Wenn Sie diese Funktion verwenden und in Cloud Run bereitstellen, erhält Ihre Funktion auch eine run.app-HTTP-Endpunkt-URL. Funktionen, die in Cloud Run erstellt werden, haben jedoch keine cloudfunctions.net-HTTP-Endpunkt-URL. Die cloudfunctions.net-URL und die run.app-URL einer Funktion verhalten sich genau gleich. Sie sind austauschbar und werden verwendet, um Ihre Funktion auszulösen.
Funktionen, die mit der Cloud Functions v2 API erstellt wurden (z. B. mit gcloud functions, der REST API oder Terraform), können sowohl mit der Cloud Run Admin API als auch mit der Cloud Functions v2 API verwaltet werden.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-08-19 (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)"]]