Cloud Functions Runtime Config
This is a wrapper around Google API Client to read Runtime Config variables in Cloud Functions.
Note: Runtime Config is currently in beta so things might break!
Installation
npm install --save cloud-functions-runtime-config
Usage
const runtimeConfig = ;const lunchPlans = runtimeConfig; exports { return lunchPlans ;};
Basic example
Enable the RuntimeConfig API
Either using the API Manager in Cloud Console or using gcloud:
gcloud service-management enable runtimeconfig.googleapis.com
Config setup
Create a config resource and store a variable in it.
gcloud beta runtime-config configs create dev-configgcloud beta runtime-config configs variables \ set lunch-plans "lets go for a hamburger!" \ --config-name dev-config
Cloud Function
A basic HTTP Function that returns the variable value.
const runtimeConfig = ;const lunchPlans = runtimeConfig; exports { return lunchPlans ;};
Deploying the Function with an HTTP trigger:
gcloud beta functions deploy lunchPlanner \ --trigger-http \ --stage-bucket=<YOUR-BUCKET>
Test the Function:
curl https://us-central1-$(gcloud config get-value core/project).cloudfunctions.net/lunchPlanner
Cleanup
gcloud beta runtime-config configs delete dev-configgcloud beta functions delete lunchPlanner
API
runtimeConfig.getVariable(config, variable)
Returns a Promise
that is either resolved to the value read from Runtime Config or rejected if the variable could not be read.
config
Type: string
variable
Type: string
runtimeConfig.getVariables(config, variables)
Returns a Promise
that is either resolved to an Array
of values or rejected if any of the variables could not be read.
The values are returned in the same order as the variableNames.
config
Type: string
variables
Type: Array<string>