Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Executar o Functions usando o emulador do Functions
Com o emulador do Functions da CLI do Google Cloud, é possível gerenciar
instâncias locais do Cloud Run functions com o comando gcloud alpha functions
local. Isso permite implantar e testar suas funções no sistema
local antes de implantá-las no
ambienteGoogle Cloud .
O emulador do Functions usa buildpacks do Google Cloud para empacotar o código da
função em imagens de contêiner executáveis localmente. Em seguida, você executa essas imagens
localmente com o Docker.
Pré-requisitos de instalação
Antes de continuar, verifique se você tem os seguintes recursos instalados:
O valor --builder assume como padrão o criador do App Engine para a
linguagem da sua função. Por exemplo, o padrão é gcr.io/serverless-runtimes/google-22-full/builder/python para Python.
Quando você usar o comando gcloud alpha pela primeira vez, o comando gcloud solicitará que você instale o conjunto de comandos gcloud alpha.
Chamar a função local
Para chamar a função local sem dados, use o seguinte comando:
gcloud alpha functions local call LOCAL_DEPLOYMENT_NAME
Substitua LOCAL_DEPLOYMENT_NAME pelo nome em que você quer implantar localmente
sua função.
A fim de incluir dados na chamada para a função local, escolha a guia
correspondente ao tipo de função:
Função HTTP
Chame a função HTTP local da seguinte maneira:
gcloud alpha functions local call LOCAL_DEPLOYMENT_NAME \
--data='{"message": "MESSAGE"}'
Substitua:
LOCAL_DEPLOYMENT_NAME: o nome em que implantar localmente
sua função.
ENTRY_POINT: o ponto de entrada da função.
MESSAGE: uma string de texto a ser transmitida como o corpo da solicitação HTTP.
Função CloudEvent
Para chamar a função local do CloudEvent, forneça um objeto JSON CloudEvent
que descreva o evento engatilhador:
gcloud alpha functions local call LOCAL_DEPLOYMENT_NAME \
--cloud-event="CLOUD_EVENT_JSON"
Substitua:
LOCAL_DEPLOYMENT_NAME: o nome em que implantar localmente
sua função.
ENTRY_POINT: o ponto de entrada da função.
CLOUD_EVENT_JSON: uma string JSON codificada no modo de conteúdo
estruturado que descreve o evento de gatilho. Para mais detalhes e exemplos, consulte
CloudEvents – formato de evento JSON.
[[["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-09-03 UTC."],[[["\u003cp\u003eThe Functions Emulator allows you to manage, deploy, and test Cloud Run functions locally before deploying them to Google Cloud using the \u003ccode\u003egcloud alpha functions local\u003c/code\u003e command.\u003c/p\u003e\n"],["\u003cp\u003ePrerequisites for using the Functions Emulator include the Google Cloud CLI, Buildpacks pack tool, and Docker, as it containerizes function code using Google Cloud's buildpacks.\u003c/p\u003e\n"],["\u003cp\u003eYou can deploy functions locally with various runtimes, including Node.js, Python, Go, Java, C#, Ruby, and PHP, using the \u003ccode\u003egcloud alpha functions local deploy\u003c/code\u003e command, and optionally configure the deployment with flags like \u003ccode\u003e--port\u003c/code\u003e and \u003ccode\u003e--builder\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eLocal functions can be called using \u003ccode\u003egcloud alpha functions local call\u003c/code\u003e which sends an HTTP POST request, or with specified data for HTTP and CloudEvent functions.\u003c/p\u003e\n"],["\u003cp\u003eYou can delete local function deployments using the \u003ccode\u003egcloud alpha functions local delete\u003c/code\u003e command, which undeploys the function but doesn't remove the function code.\u003c/p\u003e\n"]]],[],null,["# Run functions using the Functions Emulator\n==========================================\n\n|\n| **Preview**\n|\n|\n| This product or feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA products and features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nThe Google Cloud CLI *Functions Emulator* enables you to you manage\nlocal instances of your Cloud Run functions through the [gcloud alpha functions\nlocal](/sdk/gcloud/reference/alpha/functions/local) command. This lets you\ndeploy and test your functions on your local system before deploying them to the\nGoogle Cloud environment.\n\nThe Functions Emulator uses [Google Cloud's buildpacks](https://cloud.google.com/docs/buildpacks/overview) to package your function\ncode into locally-runnable container images. You then run these images\nlocally with [Docker](https://docs.docker.com/get-docker/).\n| **Note:** The `gcloud alpha functions local` command is available as an alpha pre-release, and might be unstable or change without notice. If you prefer to run your functions locally without containerization, use the [Functions Framework](/functions/1stgendocs/running/function-frameworks).\n\nInstallation prerequisites\n--------------------------\n\nBefore proceeding, make sure you have the following installed:\n\n- [Google Cloud CLI](/sdk/docs/install)\n- [Buildpacks pack tool](https://buildpacks.io/docs/tools/pack/)\n- [Docker](https://www.docker.com/get-started/)\n\nDeploy your function locally\n----------------------------\n\nTo deploy your function locally with the Functions Emulator, use the\n`gcloud functions` command: \n\n### Node.js\n\n```bash\n gcloud alpha functions local deploy LOCAL_DEPLOYMENT_NAME \\\n --entry-point=ENTRY_POINT \\\n --no-gen2 \\\n --runtime=nodejs20\n```\n\n### Python\n\n```bash\n gcloud alpha functions local deploy LOCAL_DEPLOYMENT_NAME \\\n --entry-point=ENTRY_POINT \\\n --runtime=python312\n```\n\n### Go\n\n```bash\n gcloud alpha functions local deploy LOCAL_DEPLOYMENT_NAME \\\n --entry-point=ENTRY_POINT \\\n --no-gen2 \\\n --runtime=go121\n```\n\n### Java\n\n```bash\n gcloud alpha functions local deploy LOCAL_DEPLOYMENT_NAME \\\n --entry-point=ENTRY_POINT \\\n --no-gen2 \\\n --runtime=java17 \n```\n| **Note:** Java functions use `[PACKAGE_NAME].[CLASS_NAME]` as an entry-point value.\n\n### Ruby\n\n```bash\n gcloud alpha functions local deploy LOCAL_DEPLOYMENT_NAME \\\n --entry-point=ENTRY_POINT \\\n --runtime=ruby33\n```\n\nReplace:\n\n- \u003cvar translate=\"no\"\u003eLOCAL_DEPLOYMENT_NAME\u003c/var\u003e: The name under which you are locally deploying your function.\n- \u003cvar translate=\"no\"\u003eENTRY_POINT\u003c/var\u003e: The entry point of your function.\n\nYou can further configure your deployment command with the following optional\nflags:\n\nThe `--builder` value defaults to the App Engine builder for your\nfunction's language. For example, it defaults to\n`gcr.io/serverless-runtimes/google-22-full/builder/python` for Python.\n\nWhen you first use the `gcloud alpha` command, the `gcloud` command will prompt\nyou to install the\n[gcloud alpha](https://cloud.google.com/sdk/gcloud#release_levels) command set.\n\nCall your local function\n------------------------\n\nTo call your local function without data, use the following command: \n\n gcloud alpha functions local call \u003cvar translate=\"no\"\u003eLOCAL_DEPLOYMENT_NAME\u003c/var\u003e\n\nReplace \u003cvar translate=\"no\"\u003eLOCAL_DEPLOYMENT_NAME\u003c/var\u003e with the name you want to locally\ndeploy your function under.\n| **Note:** `gcloud alpha functions local call` calls your function with an HTTP POST request. To use a different HTTP method, use a dedicated HTTP request tool such as `curl`. See [calling local functions](/functions/1stgendocs/running/calling) for instructions on how to interact with your locally-running function using `curl`.\n\nTo include data in the call to your local function, choose the tab that\nmatches your function type: \n\n### HTTP function\n\nCall your local HTTP function as follows: \n\n gcloud alpha functions local call \u003cvar translate=\"no\"\u003eLOCAL_DEPLOYMENT_NAME\u003c/var\u003e \\\n --data='{\"message\": \"\u003cvar translate=\"no\"\u003eMESSAGE\u003c/var\u003e\"}'\n\nReplace:\n\n- \u003cvar translate=\"no\"\u003eLOCAL_DEPLOYMENT_NAME\u003c/var\u003e: The name to locally deploy your function under.\n- \u003cvar translate=\"no\"\u003eENTRY_POINT\u003c/var\u003e: The entry point of your function.\n- \u003cvar translate=\"no\"\u003eMESSAGE\u003c/var\u003e: A text string to pass in as the body of the HTTP request.\n\n### CloudEvent function\n\nTo call your local CloudEvent function, you must supply a `CloudEvent` JSON\nobject describing the trigger event: \n\n gcloud alpha functions local call \u003cvar translate=\"no\"\u003eLOCAL_DEPLOYMENT_NAME\u003c/var\u003e \\\n --cloud-event=\"\u003cvar translate=\"no\"\u003eCLOUD_EVENT_JSON\u003c/var\u003e\"\n\nReplace:\n\n- \u003cvar translate=\"no\"\u003eLOCAL_DEPLOYMENT_NAME\u003c/var\u003e: The name to locally deploy your function under.\n- \u003cvar translate=\"no\"\u003eENTRY_POINT\u003c/var\u003e: The entry point of your function.\n- \u003cvar translate=\"no\"\u003eCLOUD_EVENT_JSON\u003c/var\u003e: A JSON-encoded string in structured content mode describing the triggering event. For more details and examples, see [CloudEvents - JSON event format](/eventarc/docs/workflows/cloudevents).\n\nHere is an example command line: \n\n gcloud alpha functions local call my-function --cloud-event='{\n \"specversion\" : \"1.0\",\n \"type\" : \"com.github.pull.create\",\n \"source\" : \"https://github.com/cloudevents/spec/pull\",\n \"subject\" : \"123\",\n \"id\" : \"ce\",\n \"time\" : \"2021-01-27T18:30:00Z\", \"data\" : \"{\\n \\\"subscription\\\": \\\"projects\\/test-project\\/subscriptions\\/my-subscription\\\",\\n \\\"message\\\": {\\n \\\"attributes\\\": {\\n \\\"attr1\\\":\\\"attr1-value\\\"\\n },\\n \\\"data\\\": \\\"d29ybGQ=\\\",\\n \\\"messageId\\\": \\\"message-id\\\",\\n \\\"publishTime\\\":\\\"2021-02-05T04:06:14.109Z\\\",\\n \\\"orderingKey\\\": \\\"ordering-key\\\"\\n }\\n}\"\n }'\n\nSee [CloudEvent specs](https://github.com/cloudevents/spec/blob/main/cloudevents/formats/json-format.md) for more information about how the JSON format is defined for CloudEvents.\n\nDelete your local function deployment\n-------------------------------------\n\nDelete your local function deployment with the following command: \n\n gcloud alpha functions local delete \u003cvar translate=\"no\"\u003eLOCAL_DEPLOYMENT_NAME\u003c/var\u003e\n\nReplace \u003cvar translate=\"no\"\u003eLOCAL_DEPLOYMENT_NAME\u003c/var\u003e with the name to locally deploy your\nfunction under.\n\nThis command undeploys your function but doesn't delete the function code.\n\nNext steps\n----------\n\n- Learn how to [Deploy a Cloud Run function](/functions/1stgendocs/deploy) on Google Cloud."]]