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?

3 Answers 3

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.)

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for response. Kind of sucks that this can't be defined in the configuration c_c
You're always free to file a feature request. support.google.com/firebase/contact/support
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.
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.

Comments

2

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.