Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Implantar uma função
Neste guia, você vai aprender a implantar uma função do código-fonte usando o comando
gcloud functions. Para saber como implantar uma função usando o
comando gcloud run, consulte
Implantar uma função do Cloud Run usando a CLI gcloud.
O processo de implantação recebe o código-fonte e as configurações e cria uma imagem executável que o Cloud Run functions gerencia automaticamente para processar solicitações para a função.
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.
O primeiro argumento, YOUR_FUNCTION_NAME, é um nome para a
função implantada. O nome da função deve começar com uma letra, seguida por até 62 letras, números, hífens e sublinhados, e terminar com uma letra ou um número O nome do serviço do Cloud Run que
é criado para a função substitui os sublinhados por hífens, e as letras maiúsculas são convertidas em minúsculas. Por exemplo,
Function_1 vai receber o nome function-1 no Cloud Run.
A sinalização --region
especifica a região em que a função será implantada. Consulte Locais para ver uma lista de regiões compatíveis com o Cloud Run.
A sinalização --runtime
especifica o ambiente de execução da linguagem que a função usa. Consulte
Suporte a ambientes de execução para uma lista de IDs de ambientes de execução compatíveis.
A sinalização --source
especifica o local do código-fonte da função.
A sinalização --entry-point
especifica o ponto de entrada da função no código-fonte. Este é o código que será executado quando a função for executada. O valor dessa
sinalização precisa ser um nome de função ou de classe totalmente qualificada no
código-fonte. Para mais informações, consulte
Ponto de entrada de função.
Para especificar o acionador da
função, as sinalizações adicionais (representadas como
TRIGGER_FLAGS acima) são obrigatórias, dependendo
do acionador que você quer usar:
Acione a função com o Eventarc quando um evento que corresponda aos filtros especificados ocorrer.
Para ver uma referência completa sobre o comando de implantação e as sinalizações dele, consulte a
documentação
gcloud functions deploy.
Para mais detalhes sobre flags de configuração do gcloud functions deploy,
consulte a documentação do Cloud Run.
Quando a implantação for concluída com êxito, as funções vão aparecer com uma marca de seleção
verde na página de visão geral do Cloud Run no
Google Cloud console.
A implantação inicial de uma função pode levar vários minutos, enquanto a
infraestrutura subjacente é provisionada. A reimplantação de uma função existente
é mais rápida, e o tráfego de entrada é migrado automaticamente para a versão mais recente.
URL do endpoint HTTP
Quando você cria uma função com o comando gcloud functions ou a
API Cloud Functions v2, por padrão, a função tem um
URL de endpoint HTTP cloudfunctions.net. Se você pegar essa função e implantá-la
no Cloud Run, ela também vai receber um URL de endpoint HTTP run.app. No entanto, as funções criadas no Cloud Run não têm um URL de endpoint HTTP cloudfunctions.net. O URL cloudfunctions.net e o URL run.app de uma função se comportam da mesma maneira. Eles são intercambiáveis e usados para acionar sua função.
As funções criadas usando a API Cloud Functions v2 (por exemplo, usando gcloud functions, a API REST ou o Terraform) podem ser gerenciadas com a API Cloud Run Admin e a API Cloud Functions v2.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 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)"]]