Skip to content

Feature Request: Params #1084

Closed
Closed
@inlined

Description

@inlined

We at Firebase don’t always develop in the open. It’s easier to test with a limited audience and then announce it more broadly with a PR splash. Today we’re going to go into depth about our upcoming roadmap, because Cloud Functions for Firebase is between generations of configuration options and the new features don’t seem as full-featured as the old system (yet).

We recently released support for dotenv files and Cloud Secret Manager. Many of you have noticed that, unlike Runtime Config variables, these environment variables are not available when we’re reading your code during deploys. Additionally, Runtime Config variables are not available in Cloud Functions gen 2 environments. We are aware of this feature gap and are working diligently to close it.

Runtime Config: a history

Runtime Config is a strange feature of Cloud Functions for Firebase that exists purely for historic reasons. Runtime Config was originally conceived to allow Cloud Functions for Firebase to dynamically be reconfigured without redeployment. Unfortunately, this flopped during alpha testing: reading the initial state of Runtime Config added about 100ms to cold start latency and any transient outage in Runtime Config would cause uncatchable failures in your Cloud Functions. After discovering this, we immediately removed the “realtime” features of Runtime Config. We kept a dependency on Runtime Config because it served another purpose: it was a way to add “config” values at a time where Cloud Functions did not yet support environment variables.

For configuration at runtime, environment variables and cloud secrets manager are always a better solution. They are standards compliant, keep secrets out of prying eyes, and have emulator support built in. Runtime Config will not exit beta and we’ve been asked to move customers off of it. The removal of Runtime Config support in the firebase-functions SDK and firebase-tools CLI will be announced once their replacement is ready.

Params: the future

Params are an upcoming layer atop of the existing support for environment variables and Cloud Secret manager. They will be very easy to use:

const language = params.defineString(“LANGUAGE”, {
  description: “What language to translate into”
});

export const translate = functions.database.ref(“/messages/{id}”).onCreate(await (ref) => {
  const translated = await translateInto(ref.child(“original”).data(), language.val);
  // …
});

Here, your code depends on the environment variable LANGUAGE at runtime. But this has a few benefits over simple environment variables. The first is that Firebase knows your code needs a “LANGUAGE” environment variable. If we don’t see one, we will prompt you for its value during deploy. This makes it harder to push broken apps to production and makes it easy to get set up with sample code.

The value of a param cannot be read during deploy time, but they can be used to templatize your code:

const bucket = params.defineResource(“BUCKET”, {
  type: “resourceSelector”
  resourceType: “storage.googleapis.com/Bucket”,
});

// bucket.val is the empty string during deploy, but you can assign any attribute of your cloud
// function (e.g. the bucket, your region, min instance counts) and your code will be templatized
export const thumbnail = functions.storage.bucket(bucket).onObjectFinalized((object) => {/*...*/});

We see this as the future because it allows us to provide better features. In the example above, we can provide a dialog that prompts you for a Cloud Storage bucket if your config is missing. The Runtime Config analog would just behave unexpectedly. This feature will make it much easier for developers to create and use templatized sample code or even their own Firebase Extensions. Stay tuned, the future is bright!

Sincerely,
The Firebase team

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions