Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Men-deploy fungsi
Panduan ini menunjukkan cara men-deploy fungsi dari kode sumber menggunakan
perintah gcloud functions. Untuk mempelajari cara men-deploy fungsi menggunakan perintah
gcloud run, lihat
Men-deploy fungsi Cloud Run menggunakan gcloud CLI.
Proses deployment mengambil kode sumber dan setelan konfigurasi Anda, serta membuat image yang dapat dijalankan yang dikelola Cloud Run functions secara otomatis untuk menangani permintaan ke fungsi Anda.
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.
Argumen pertama, YOUR_FUNCTION_NAME, adalah nama untuk fungsi yang di-deploy. Nama fungsi harus dimulai dengan huruf yang diikuti dengan maksimal 62 huruf, angka, tanda hubung, atau garis bawah, dan harus diakhiri dengan huruf atau angka. Nama layanan Cloud Run yang dibuat untuk fungsi Anda akan mengganti garis bawah dengan tanda hubung dan huruf besar akan dikonversi menjadi huruf kecil. Misalnya,
Function_1 akan diberi nama function-1 di Cloud Run.
Flag --region menentukan region tempat men-deploy fungsi Anda. Lihat
Lokasi untuk mengetahui daftar region yang didukung oleh
Cloud Run.
Flag --runtime menentukan runtime bahasa yang digunakan fungsi Anda. Lihat
Dukungan runtime untuk mengetahui daftar ID runtime yang didukung.
Flag --source menentukan lokasi kode sumber fungsi Anda.
Flag --entry-point
menentukan titik masuk ke fungsi Anda dalam kode sumber. Ini adalah kode yang akan dijalankan saat fungsi Anda berjalan. Nilai flag ini harus berupa nama fungsi atau nama class yang sepenuhnya memenuhi syarat yang ada dalam kode sumber Anda. Untuk mengetahui informasi selengkapnya, lihat
Titik entri fungsi.
Untuk menentukan pemicu fungsi Anda, flag tambahan (ditunjukkan sebagai TRIGGER_FLAGS di atas) diperlukan, bergantung pada pemicu yang ingin Anda gunakan:
Memicu fungsi dengan Eventarc saat ada peristiwa yang cocok dengan filter yang ditentukan.
Untuk referensi lengkap tentang perintah deployment dan flag-nya, lihat dokumentasi gcloud functions deploy.
Untuk mengetahui detail selengkapnya tentang flag konfigurasi gcloud functions deploy, lihat dokumentasi Cloud Run.
Setelah deployment berhasil, fungsi akan muncul dengan tanda centang hijau di halaman ringkasan Cloud Run di
konsolGoogle Cloud .
Deployment awal fungsi mungkin memerlukan waktu beberapa menit, sementara infrastruktur yang mendasarinya disiapkan. Deployment ulang fungsi yang ada akan lebih cepat, dan traffic yang masuk akan otomatis dimigrasikan ke versi terbaru.
URL endpoint HTTP
Saat Anda membuat fungsi dengan perintah gcloud functions atau
Cloud Functions v2 API, secara default, fungsi tersebut memiliki
URL endpoint HTTP cloudfunctions.net. Jika Anda mengambil fungsi ini dan men-deploy-nya di Cloud Run, fungsi Anda juga akan menerima URL endpoint HTTP run.app. Namun, fungsi yang dibuat di Cloud Run tidak akan memiliki URL endpoint HTTP cloudfunctions.net. URL cloudfunctions.net dan URL run.app fungsi berperilaku sama persis. Keduanya dapat dipertukarkan,
dan digunakan untuk memicu fungsi Anda.
Fungsi yang dibuat menggunakan Cloud Functions v2 API
(misalnya, dengan menggunakan gcloud functions, REST API, atau Terraform) dapat
dikelola dengan Cloud Run Admin API
serta Cloud Functions v2 API.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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)"]]