4

Is there a way of defining which region to use when deploying a function to firebase using either the firebase.json or the .firebaserc files? The documentation around this doesn't seem to be clear.

Deploying the firebase functions using GitHub Actions and want to avoid adding the region in the code itself if possible.

Suggestions?

Skaleb
  • 308
  • 2
  • 10

3 Answers3

3

It's not possible using the configurations you mention. The region must be defined synchronously in code using the provided API. You could perhaps pull in an external JSON file using fs.readFileSync() at the global scope of index.js, parse its contents, and apply them to the function builder. (Please note that you have to do this synchronously - you can't use a method that returns a promise.)

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • 1
    Thanks for response. Kind of sucks that this can't be defined in the configuration c_c – Skaleb May 06 '20 at 21:03
  • 1
    You're always free to file a feature request. https://support.google.com/firebase/contact/support – Doug Stevenson May 06 '20 at 21:18
  • I use Angular + SSR and deploy the App via Cloud Functions. When I run `firebase deploy` the file index.js is generated and the function it contains uses `us-central1` as default region. Can I customize this generated file in any way? E.g. set the region to `europe-west3`. – Blank Jul 03 '20 at 06:09
3

I've target this problem using native functions config.
Example:

firebase functions:config:set functions.region=southamerica-east1

Then in functions declaration I'd as follows:

const { region } = functions.config().functions;
    
exports.myFunction = functions.region(region).https.onCall((data) => {
  // do something
});

That way, for each time I need a different region, it would only need a new config set.

Víctor Hugo
  • 233
  • 1
  • 10
1

As of Firebase tools version v11.24.0, functions region can now be set for full-stack web frameworks.

Example of config:

{
  "hosting": {
    "source": ".",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "frameworksBackend": {
      "region": "europe-west1"
    }
  }
}

You can read more here and here.

Note: This will only work for framework-aware hosting, (like this).

Rusu Dinu
  • 477
  • 2
  • 5
  • 16