Extend Remote Config with Cloud Functions

You can trigger a function in response toRemote Config events, includingthe publication of a new config version or the rollback to an older version.This guide describes how to create aRemote Config background functionthat performs a diff of two template versions.

Trigger aRemote Config function

To trigger aRemote Config function, first import therequired modules:

Node.js

// The Cloud Functions for Firebase SDK to set up triggers and logging.const{onConfigUpdated}=require("firebase-functions/remoteConfig");constlogger=require("firebase-functions/logger");// The Firebase Admin SDK to obtain access tokens.constadmin=require("firebase-admin");constapp=admin.initializeApp();constjsonDiff=require("json-diff");

Python

# The Cloud Functions for Firebase SDK to set up triggers and logging.fromfirebase_functionsimportremote_config_fn# The Firebase Admin SDK to obtain access tokens.importfirebase_adminapp=firebase_admin.initialize_app()importdeepdiffimportrequests

Then define a handler for the update event. The event object passed tothis function contains metadataabout a template update, such as the new version number and time of the update.You can also retrieve the email for the user who made the update, with nameand an image if available.

Here's an example of aRemote Config function thatlogs a diff of each updated version and the version it replaced. The functionexamines the version number field of the template object and retrieves thecurrent (newly updated) version together with the version one number lower:

Node.js

exports.showconfigdiff=onConfigUpdated(async(event)=>{try{// Obtain the access token from the Admin SDKconstaccessTokenObj=awaitadmin.credential.applicationDefault().getAccessToken();constaccessToken=accessTokenObj.access_token;// Get the version number from the event objectconstremoteConfigApi="https://firebaseremoteconfig.googleapis.com/v1/"+`projects/${app.options.projectId}/remoteConfig`;constcurrentVersion=event.data.versionNumber;constprevVersion=currentVersion-1;consttemplatePromises=[];templatePromises.push(fetch(remoteConfigApi,{method:"POST",body:newURLSearchParams([["versionNumber",currentVersion+""]]),headers:{Authorization:"Bearer "+accessToken},},));templatePromises.push(fetch(remoteConfigApi,{method:"POST",body:newURLSearchParams([["versionNumber",prevVersion+""]]),headers:{Authorization:"Bearer "+accessToken},},));// Get the templatesconstresponses=awaitPromise.all(templatePromises);constresults=responses.map((r)=>r.json());constcurrentTemplate=results[0];constpreviousTemplate=results[1];// Figure out the differences of the templatesconstdiff=jsonDiff.diffString(previousTemplate,currentTemplate);// Log the differencelogger.log(diff);}catch(error){logger.error(error);}});

This sample uses thejson-diff andrequest-promise modules tocreate the diff and build the request to get the template object.

Python

@remote_config_fn.on_config_updated()defshowconfigdiff(event:remote_config_fn.CloudEvent[remote_config_fn.ConfigUpdateData])->None:"""Log the diff of the most recent Remote Config template change."""# Obtain an access token from the Admin SDKaccess_token=app.credential.get_access_token().access_token# Get the version number from the event objectcurrent_version=int(event.data.version_number)# Figure out the differences between templatesremote_config_api=("https://firebaseremoteconfig.googleapis.com/v1/"f"projects/{app.project_id}/remoteConfig")current_template=requests.get(remote_config_api,params={"versionNumber":current_version},headers={"Authorization":f"Bearer{access_token}"})previous_template=requests.get(remote_config_api,params={"versionNumber":current_version-1},headers={"Authorization":f"Bearer{access_token}"})diff=deepdiff.DeepDiff(previous_template,current_template)# Log the differenceprint(diff.pretty())

This sample usesdeepdiff tocreate the diff, andrequests to build and send the request to getthe template object.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-18 UTC.