[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-03。"],[[["\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."]]