Jika Anda membuat fungsi baru, lihat Panduan Memulai Konsol di Cloud Run. Konten di halaman ini hanya berlaku untuk fungsi lama yang sudah ada yang dibuat dengan Cloud Functions v1 API.
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Pemicu Firebase Remote Config
Fungsi Cloud Run dapat dipicu sebagai respons terhadap perubahan Firebase Remote Config dalam project Google Cloud yang sama dengan fungsi. Hal ini memungkinkan Anda mengubah perilaku dan tampilan aplikasi tanpa memublikasikan update aplikasi.
Jenis peristiwa
Firebase Remote Config dapat memicu fungsi sebagai respons terhadap peristiwa remoteconfig.update.
Jenis Peristiwa
Pemicu
remoteconfig.update
Dipicu saat template remote config diperbarui.
Struktur peristiwa
Data peristiwa disediakan sebagai objek remoteConfig yang ditransformasi.
/** * Background Function triggered by a change to a Firebase Remote Config value. * * @param {object} event The Cloud Functions event. */exports.helloRemoteConfig=event=>{console.log(`Update type: ${event.updateType}`);console.log(`Origin: ${event.updateOrigin}`);console.log(`Version: ${event.versionNumber}`);};
Python
defhello_remote_config(data,context):"""Triggered by a change to a Firebase Remote Config value. Args: data (dict): The event payload. context (google.cloud.functions.Context): Metadata for the event. """print(f'Update type: {data["updateType"]}')print(f'Origin: {data["updateOrigin"]}')print(f'Version: {data["versionNumber"]}')
Go
// Package helloworld provides a set of Cloud Functions samples.packagehelloworldimport("context""log")// A RemoteConfigEvent is an event triggered by Firebase Remote Config.typeRemoteConfigEventstruct{UpdateOriginstring`json:"updateOrigin"`UpdateTypestring`json:"updateType"`UpdateUserstruct{Emailstring`json:"email"`ImageURLstring`json:"imageUrl"`Namestring`json:"name"`}`json:"updateUser"`VersionNumberstring`json:"versionNumber"`}// HelloRemoteConfig handles Firebase Remote Config events.funcHelloRemoteConfig(ctxcontext.Context,eRemoteConfigEvent)error{log.Printf("Update type: %v",e.UpdateType)log.Printf("Origin: %v",e.UpdateOrigin)log.Printf("Version: %v",e.VersionNumber)returnnil}
Java
importcom.google.cloud.functions.Context;importcom.google.cloud.functions.RawBackgroundFunction;importcom.google.gson.Gson;importcom.google.gson.JsonObject;importjava.util.logging.Logger;publicclassFirebaseRemoteConfigimplementsRawBackgroundFunction{privatestaticfinalLoggerlogger=Logger.getLogger(FirebaseRemoteConfig.class.getName());// Use GSON (https://github.com/google/gson) to parse JSON content.privatestaticfinalGsongson=newGson();@Overridepublicvoidaccept(Stringjson,Contextcontext){JsonObjectbody=gson.fromJson(json,JsonObject.class);if(body!=null){if(body.has("updateType")){logger.info("Update type: "+body.get("updateType").getAsString());}if(body.has("updateOrigin")){logger.info("Origin: "+body.get("updateOrigin").getAsString());}if(body.has("versionNumber")){logger.info("Version: "+body.get("versionNumber").getAsString());}}}}
C#
usingCloudNative.CloudEvents;usingGoogle.Cloud.Functions.Framework;usingGoogle.Events.Protobuf.Firebase.RemoteConfig.V1;usingMicrosoft.Extensions.Logging;usingSystem.Threading;usingSystem.Threading.Tasks;namespaceFirebaseRemoteConfig;publicclassFunction:ICloudEventFunction<RemoteConfigEventData>{privatereadonlyILogger_logger;publicFunction(ILogger<Function>logger)=>
_logger=logger;publicTaskHandleAsync(CloudEventcloudEvent,RemoteConfigEventDatadata,CancellationTokencancellationToken){_logger.LogInformation("Update type: {origin}",data.UpdateType);_logger.LogInformation("Update origin: {origin}",data.UpdateOrigin);_logger.LogInformation("Version number: {version}",data.VersionNumber);// In this example, we don't need to perform any asynchronous operations, so the// method doesn't need to be declared async.returnTask.CompletedTask;}}
Ruby
require"functions_framework"# Triggered by a change to a Firebase Remote Config valueFunctionsFramework.cloud_event"hello_remote_config"do|event|# Event-triggered Ruby functions receive a CloudEvents::Event::V1 object.# See https://cloudevents.github.io/sdk-ruby/latest/CloudEvents/Event/V1.html# The Firebase event payload can be obtained from the event data.payload=event.datalogger.info"Update type: #{payload['updateType']}"logger.info"Origin: #{payload['updateOrigin']}"logger.info"Version: #{payload['versionNumber']}"end
Nama terdaftar fungsi Cloud Run yang sedang Anda deploy.
Ini dapat berupa nama fungsi dalam kode sumber Anda, atau string arbitrer. Jika FUNCTION_NAME adalah string arbitrer, Anda harus menyertakan flag --entry-point.
--entry-point ENTRY_POINT
Nama fungsi atau class dalam kode sumber Anda. Opsional, kecuali jika Anda tidak menggunakan FUNCTION_NAME untuk menentukan fungsi dalam kode sumber yang akan dijalankan selama deployment. Dalam hal ini, Anda harus menggunakan --entry-point untuk memberikan nama fungsi yang dapat dieksekusi.
[[["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\u003eFirebase Remote Config triggers allow Cloud Run functions to respond to changes in Firebase Remote Config, enabling dynamic app behavior and appearance updates without app store releases.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eremoteconfig.update\u003c/code\u003e event type triggers functions whenever the Remote Config template is updated, providing real-time adaptability.\u003c/p\u003e\n"],["\u003cp\u003eEvent data for Remote Config updates includes \u003ccode\u003eupdateType\u003c/code\u003e, \u003ccode\u003eupdateOrigin\u003c/code\u003e, and \u003ccode\u003eversionNumber\u003c/code\u003e, offering detailed information about the configuration change.\u003c/p\u003e\n"],["\u003cp\u003eBeta triggers for Remote Config may have evolving formats for CloudEvents, particularly in the \u003ccode\u003eSource\u003c/code\u003e, \u003ccode\u003eSubject\u003c/code\u003e, and data payload, so adaptations may be needed.\u003c/p\u003e\n"],["\u003cp\u003eDeploying functions with Firebase Remote Config triggers requires specifying \u003ccode\u003egoogle.firebase.remoteconfig.update\u003c/code\u003e as the trigger event, alongside the function name, entry point, and runtime environment.\u003c/p\u003e\n"]]],[],null,["# Firebase Remote Config Triggers\n===============================\n\n|\n| **Beta**\n|\n|\n| This feature is covered by the\n| [Pre-GA Offerings Terms](/terms/service-terms#1) of the Google Cloud\n| Terms of Service. Pre-GA features may have limited support, and changes\n| to pre-GA features may not be compatible with other pre-GA versions.\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n|\n|\n| Specifically, note that\n| [CloudEvents](/functions/1stgendocs/writing/write-event-driven-functions) that are\n| generated by Beta triggers may change format over time. The `Source`\n| and `Subject` attributes, additional extension attributes, and the\n| data (payload) format are all subject to change.\n\nCloud Run functions can be triggered in response to changes in\n[Firebase Remote Config](https://firebase.google.com/docs/remote-config) in the\nsame Google Cloud project as the function. This makes it possible to change\nthe behavior and appearance of your app without publishing an app update.\n\nEvent types\n-----------\n\nFirebase Remote Config can trigger functions in response to the\n`remoteconfig.update` event.\n\nEvent structure\n---------------\n\nEvent data is provided as a transformed [`remoteConfig` object](https://firebase.google.com/docs/reference/remote-config/rest/v1/RemoteConfig).\n\nFor example: \n\n```bash\n{\n \"updateType\": \"FORCED_UPDATE\",\n \"updateOrigin\": \"CONSOLE\",\n \"versionNumber\": 1\n}\n```\n\nSample code\n-----------\n\n### Node.js\n\n /**\n * Background Function triggered by a change to a Firebase Remote Config value.\n *\n * @param {object} event The Cloud Functions event.\n */\n exports.helloRemoteConfig = event =\u003e {\n console.log(`Update type: ${event.updateType}`);\n console.log(`Origin: ${event.updateOrigin}`);\n console.log(`Version: ${event.versionNumber}`);\n };\n\n### Python\n\n def hello_remote_config(data, context):\n \"\"\"Triggered by a change to a Firebase Remote Config value.\n Args:\n data (dict): The event payload.\n context (google.cloud.functions.Context): Metadata for the event.\n \"\"\"\n print(f'Update type: {data[\"updateType\"]}')\n print(f'Origin: {data[\"updateOrigin\"]}')\n print(f'Version: {data[\"versionNumber\"]}')\n\n### Go\n\n\n // Package helloworld provides a set of Cloud Functions samples.\n package helloworld\n\n import (\n \t\"context\"\n \t\"log\"\n )\n\n // A RemoteConfigEvent is an event triggered by Firebase Remote Config.\n type RemoteConfigEvent struct {\n \tUpdateOrigin string `json:\"updateOrigin\"`\n \tUpdateType string `json:\"updateType\"`\n \tUpdateUser struct {\n \t\tEmail string `json:\"email\"`\n \t\tImageURL string `json:\"imageUrl\"`\n \t\tName string `json:\"name\"`\n \t} `json:\"updateUser\"`\n \tVersionNumber string `json:\"versionNumber\"`\n }\n\n // HelloRemoteConfig handles Firebase Remote Config events.\n func HelloRemoteConfig(ctx context.Context, e RemoteConfigEvent) error {\n \tlog.Printf(\"Update type: %v\", e.UpdateType)\n \tlog.Printf(\"Origin: %v\", e.UpdateOrigin)\n \tlog.Printf(\"Version: %v\", e.VersionNumber)\n \treturn nil\n }\n\n### Java\n\n import com.google.cloud.functions.Context;\n import com.google.cloud.functions.RawBackgroundFunction;\n import com.google.gson.Gson;\n import com.google.gson.JsonObject;\n import java.util.logging.Logger;\n\n public class FirebaseRemoteConfig implements RawBackgroundFunction {\n private static final Logger logger = Logger.getLogger(FirebaseRemoteConfig.class.getName());\n\n // Use GSON (https://github.com/google/gson) to parse JSON content.\n private static final Gson gson = new Gson();\n\n @Override\n public void accept(String json, Context context) {\n JsonObject body = gson.fromJson(json, JsonObject.class);\n\n if (body != null) {\n if (body.has(\"updateType\")) {\n logger.info(\"Update type: \" + body.get(\"updateType\").getAsString());\n }\n if (body.has(\"updateOrigin\")) {\n logger.info(\"Origin: \" + body.get(\"updateOrigin\").getAsString());\n }\n if (body.has(\"versionNumber\")) {\n logger.info(\"Version: \" + body.get(\"versionNumber\").getAsString());\n }\n }\n }\n }\n\n### C#\n\n```c#\nusing CloudNative.CloudEvents;\nusing Google.Cloud.Functions.Framework;\nusing Google.Events.Protobuf.Firebase.RemoteConfig.V1;\nusing Microsoft.Extensions.Logging;\nusing System.Threading;\nusing System.Threading.Tasks;\n\nnamespace FirebaseRemoteConfig;\n\npublic class Function : ICloudEventFunction\u003cRemoteConfigEventData\u003e\n{\n private readonly ILogger _logger;\n\n public Function(ILogger\u003cFunction\u003e logger) =\u003e\n _logger = logger;\n\n public Task HandleAsync(CloudEvent cloudEvent, RemoteConfigEventData data, CancellationToken cancellationToken)\n {\n _logger.LogInformation(\"Update type: {origin}\", data.UpdateType);\n _logger.LogInformation(\"Update origin: {origin}\", data.UpdateOrigin);\n _logger.LogInformation(\"Version number: {version}\", data.VersionNumber);\n\n // In this example, we don't need to perform any asynchronous operations, so the\n // method doesn't need to be declared async.\n return Task.CompletedTask;\n }\n}\n```\n\n### Ruby\n\n require \"functions_framework\"\n\n # Triggered by a change to a Firebase Remote Config value\n FunctionsFramework.cloud_event \"hello_remote_config\" do |event|\n # Event-triggered Ruby functions receive a CloudEvents::Event::V1 object.\n # See https://cloudevents.github.io/sdk-ruby/latest/CloudEvents/Event/V1.html\n # The Firebase event payload can be obtained from the event data.\n payload = event.data\n\n logger.info \"Update type: #{payload['updateType']}\"\n logger.info \"Origin: #{payload['updateOrigin']}\"\n logger.info \"Version: #{payload['versionNumber']}\"\n end\n\n### PHP\n\n```php\nuse Google\\CloudFunctions\\CloudEvent;\n\nfunction firebaseRemoteConfig(CloudEvent $cloudevent)\n{\n $log = fopen(getenv('LOGGER_OUTPUT') ?: 'php://stderr', 'wb');\n\n $data = $cloudevent-\u003egetData();\n\n fwrite($log, 'Update type: ' . $data['updateType'] . PHP_EOL);\n fwrite($log, 'Origin: ' . $data['updateOrigin'] . PHP_EOL);\n fwrite($log, 'Version: ' . $data['versionNumber'] . PHP_EOL);\n}\n```\n\n### Deploying your function\n\nTo deploy your function, you need to specify the event type\n`google.firebase.remoteconfig.update`.\n\nThe following `gcloud` command deploys a function that is triggered\nby a Firebase Remote Config event: \n\n```bash\ngcloud functions deploy FUNCTION_NAME \\\n --no-gen2 \\\n --entry-point ENTRY_POINT \\\n --trigger-event google.firebase.remoteconfig.update \\\n --runtime RUNTIME\n```\n| **Note:** When you deploy a function using the Google Cloud CLI, the command must include the name of the function contained in your code that you want the `deploy` command to execute. You can specify that function using either `FUNCTION_NAME` or the optional `--entry-point` flag, depending on the needs of your implementation. See the [deployment guide](/functions/1stgendocs/deploy#basics) for more discussion."]]