Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Esegui il deployment di una funzione
Questa guida mostra come eseguire il deployment di una funzione dal codice sorgente utilizzando il comando
gcloud functions. Per scoprire come eseguire il deployment di una funzione utilizzando il comando
gcloud run, consulta
Esegui il deployment di una funzione Cloud Run utilizzando gcloud CLI.
Il processo di deployment prende il codice sorgente e le impostazioni di configurazione e crea un'immagine eseguibile che Cloud Run Functions gestisce automaticamente per gestire le richieste alla tua funzione.
Nozioni di base sul deployment
Per un'introduzione al tipo di funzioni che puoi eseguire il deployment, consulta
Scrivere funzioni Cloud Run.
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.
Il primo argomento, YOUR_FUNCTION_NAME, è un nome per
la funzione di cui è stato eseguito il deployment. Il nome della funzione deve iniziare con una lettera
seguita da un massimo di 62 lettere, numeri, trattini o trattini bassi e deve terminare
con una lettera o un numero. Il nome del servizio Cloud Run creato per la tua funzione sostituirà i trattini bassi con trattini e le lettere maiuscole verranno convertite in minuscole. Ad esempio,
Function_1 riceverà il nome function-1 in Cloud Run.
Il flag --region
specifica la regione in cui eseguire il deployment della funzione. Consulta
Località per un elenco delle regioni supportate da
Cloud Run.
Il flag --runtime
specifica il runtime della lingua utilizzato dalla funzione. Consulta la sezione
Supporto del runtime per un elenco degli ID runtime
supportati.
Il flag --source
specifica la posizione del codice sorgente della funzione.
Il flag --entry-point
specifica il punto di ingresso della funzione nel codice sorgente. Questo è
il codice che verrà eseguito quando viene eseguita la funzione. Il valore di questo
flag deve essere un nome di funzione o un nome di classe completo esistente nel
codice sorgente. Per saperne di più, consulta
Punto di ingresso della funzione.
Per specificare il trigger per la tua funzione, sono necessari flag aggiuntivi (rappresentati come TRIGGER_FLAGS sopra), a seconda del trigger che vuoi utilizzare:
Attiva la funzione con Eventarc quando si verifica un evento che corrisponde ai filtri specificati.
Per un riferimento completo al comando di deployment e ai relativi flag, consulta la documentazione
gcloud functions deploy.
Per ulteriori dettagli sui flag di configurazione di gcloud functions deploy,
consulta la documentazione di Cloud Run.
Al termine del deployment, le funzioni vengono visualizzate con un segno di spunta verde nella pagina Panoramica di Cloud Run nella consoleGoogle Cloud .
Il deployment iniziale di una funzione potrebbe richiedere diversi minuti, mentre viene eseguito il provisioning dell'infrastruttura sottostante. Il redeployment di una funzione esistente
è più rapido e il traffico in entrata viene migrato automaticamente alla versione più recente.
URL endpoint HTTP
Quando crei una funzione con il comando gcloud functions o l'API Cloud Functions v2, per impostazione predefinita la funzione ha un URL endpoint HTTP cloudfunctions.net. Se prendi questa funzione ed esegui il deployment
su Cloud Run, la funzione riceve anche un URL dell'endpoint HTTP run.app. Tuttavia, le funzioni create in Cloud Run non avranno un
URL dell'endpoint HTTP cloudfunctions.net. L'URL cloudfunctions.net e l'URL run.app di una funzione si comportano esattamente allo stesso modo. Sono intercambiabili
e vengono utilizzati per attivare la funzione.
Le funzioni create utilizzando l'API Cloud Functions v2
(ad esempio utilizzando gcloud functions, l'API REST o Terraform) possono essere
gestite con l'API Cloud Run Admin
e con l'API Cloud Functions v2.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-03 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)"]]