Cloud Functions

Environment Var and Config

Function Environment variables is essentially using this beta feature from GCP: https://cloud.google.com/deployment-manager/runtime-configurator/set-and-get-variables​
To set in firebase environment do
firebase functions:config:set aws.aws_access_key_id="XXXX" aws.aws_scret_access_key="XXXX"

Using env var Locally

For this to run locally: firebase functions:config:get > .runtimeconfig.json in functions folder, also add to .gitignore

Storage Triggers

Since you cannot configure a function to be triggered by subdirectories. It's only possible to listen to the entire bucket. If you have a trigger based on Bucket, the recommendation is to create a new, separate bucket so that you are not triggered every time a file changes in the Bucket.
  1. 1.
    Create a new bucket
  2. 2.
    Update your Functions environment config with new bucket name
  3. 3.
    Call the functions.config() to get the specified bucket name
You can do environments for Functions:
1
$ firebase -P dev functions:config:set storage.bucket="dev-digital-paper-edit"
2
> βœ” Functions config updated.
3
​
4
$ firebase -P dev functions:config:get
5
> {
6
"storage": {
7
"bucket": "dev-digital-paper-edit"
8
}
9
}
10
$ firebase -P prod functions:config:get
11
> {}
Copied!
And then subsequently in a Function you'd use the config like so:
1
const functions = require("firebase-functions");
2
const BucketFunctions = functions.storage.object(
3
functions.config().storage.bucket
4
);
Copied!

Caveat

A big caveat here - you don't have a document anywhere in your repo that tells you what this is. You need to be logged in into firebase and run the above
1
firebase -P dev functions:config:get
Copied!
command to know what this is.
Last modified 1yr ago