Firebase-tools: Hosting doesn't execute function if function region is not default

Created on 28 Jul 2018  ·  41Comments  ·  Source: firebase/firebase-tools

Version info

4.00

Platform Information

OS X

Steps to reproduce

function deployed to europe-west1

// function code
const functions = require('firebase-functions');

exports.helloIvanA = functions
  .region('europe-west1')
  .https.onRequest((request, response) => {
    response.send('Hello from Ivan!');
  });

// firebase.json
{
  "hosting": {
    "public": "public",

    "rewrites": [
      {
        "source": "**",
        "function": "helloIvanA"
      }
    ]
  }
}

Expected behavior

https://blablabla.firebaseapp.com will get data from helloIvanA

Actual behavior

https://blablabla.firebaseapp.com redirects to https://us-central1-yushkarala.cloudfunctions.net/helloIvanA/
and gives
Error: Forbidden Your client does not have permission to get URL /helloIvanA/ from this server.

Most helpful comment

Would love to see this implemented. My visitors are from Europe, and the TTFB from us-central1 is at least 3x bigger than europe-west1.

All 41 comments

Hi, this is expected behavior, please see https://firebase.google.com/docs/functions/locations#http_and_client_callable_functions, the blue box indicates that all functions that serve as hosting redirects must be in 'us-central1', this is due to the fact that that's where the hosting origin is.

Thank you, any chance that this expected behaviour will be changed in near future or at least in a future?

Hi, it will change in a future, but not in the near future. It depends on when Firebase Hosting launch origins in other geographies.

Hello,
My problem is very similar to this, but my functions should be in the EU, as it uses external network, and the latency is much better in this way (2-4 sec vs 4-600 ms) execution time
Described my problem in:
https://github.com/firebase/firebase-js-sdk/issues/1101
so there is no solution yet to use rewrites to an other region at the moment?
( I've a workaround, using direct links to reach the EU function, but that not ideal from development side, I need to redeploy everything to test it out)

Would love to see this implemented. My visitors are from Europe, and the TTFB from us-central1 is at least 3x bigger than europe-west1.

Hi, it will change in a future, but not in the near future. It depends on when Firebase Hosting launch origins in other geographies.

Hi @laurenzlong ,

does that mean that when Hosting will be available through other locations that us-central1, we'll also be able to bypass the following limitation ?
Important: If you are using HTTP functions to serve dynamic content for hosting, you must use us-central1. from doc

I need that feature for my application. So, the sooner, the better :)!

Thanks a lot for all this.

A warning in bold should be written until this is fixed. I've spent too much time until I realized what happens.
At least add a region option to the rewrites so we can redirect to europe.

Hope cloud function for Firebase support region option like cloud run setting did. I'm using tokyo region. It is really far from us-central1.

does that mean that when Hosting will be available through other locations that us-central1, we'll also be able to bypass the following limitation ?
Important: If you are using HTTP functions to serve dynamic content for hosting, you must use us-central1. from doc

Hi @laurenzlong ,

do you have any (good)? news about this ?

I agree that as @wangchou said, cloud run would be an alternative, but it adds stack of services / technology.

Hoping to read you soon. Thanks!

We're still looking into this but right now our origin infrastructure is concentrated in us-central which means that allowing function proxying in other regions would end up creating extra latency in most cases. For instance:

tokyo -> CDN edge -> origin (us-central) -> function (tokyo)

This means that the round trip time actually does something like doubling.

We are investigating expanding the locations of our origin infrastructure, but until then we're wary about adding this capability as it is more likely to cause harm than good.

@mbleigh - Please could you give us any estimates when Hosting origin will be located outside of US?

The whole Firebase environment is amazing, but this make us think twice before switching to it. Thank you

Really don't know why this issue has been closed if it has been not resolved, bumping +1.

Second this, Firebase is amazing, but for European users this is a major caveat.

Sorry, we can't comment on timelines as they are a little too subject to change. I appreciate the ongoing voice for supporting this as a feature, that's definitely something we take into account as we plan and build the product.

I have an issue that might be related to this, but I do not fully understand this so I do not know. If someone who knows better and have time wants to comment on that, please see this question:

https://stackoverflow.com/questions/57367131/403-from-deployed-firebase-function

Would be a great thing to have this, we could finally add a hosting rewrite to our functions already living in europe-west1.

Would be great indeed. For now, also using redirects as @hgghyxo mentioned:

Function name api
Region europe-west1

firebase.json

"redirects": {
    {
          "source": "/api/endpoint",
          "destination": "https://europe-west1-project-id.cloudfunctions.net/api/endpoint",
          "type": 301
    },
    ...
}

@mcoevert commented on Aug 19, 2019, 10:36 AM GMT+2:

Would be great indeed. For now, also using redirects as @hgghyxo mentioned:

Redirects won't solve the CORS issues though.

Would like to see europe-region support too.

It seems that a rewrite can now be made with a Cloud Run service hosted on europe-west1 region (currently the only europe region available for Cloud Run). It's not quite the same, but pretty close.

Hi, this is expected behavior, please see https://firebase.google.com/docs/functions/locations#http_and_client_callable_functions, the blue box indicates that all functions that serve as hosting redirects must be in 'us-central1', this is due to the fact that that's where the hosting origin is.

Sorry but a tiny blue box is easily missed. We've wasted too many hours on this problem, thinking it was a configuration problem in our end.

Why is this closed - it's an issue for us in europe. Is there any explanation why it's only working for region us ?

This issue is closed because it's a feature request for Firebase Hosting that can't be addressed directly in the Firebase CLI. Feature requests are tracked internally and I'd encourage you to request support for additional regions via this form.

We are definitely aware that many of you want this feature, thanks for the feedback!

This issue is closed because it's a feature request for Firebase Hosting that can't be addressed directly in the Firebase CLI. Feature requests are tracked internally and I'd encourage you to request support for additional regions via this form.

We are definitely aware that many of you want this feature, thanks for the feedback!

Feature requests are only tracked internally? Doesn't that bring a lot of duplicate requests? I'd like to show support for these features to include non-US regions.

Yes -- if you send a feature request, we will deduplicate it against other ones for our internal tracking (and it definitely helps to show more support for requests!).

You could use Cloud Run instead of a Cloud Function if you don't need a VPC.  Cloud Run (fully managed) cannot connect to VPC network currently. A workaround I've tested to use the VPC + custom domain + Cloud Function is to use a Cloud Run with a custom domain which is a proxy to the Cloud Function. It adds a bit of overhead but if your Cloud Run and Cloud  Function are in the same region then, in theory, it shouldn't be much latency. That being said, I've monitored it over a month and Cloud Run beta is not 100% that stable: 

image

This is a repo with the proxy I've used if you want to deploy it to Cloud Run and give it a try https://github.com/reactgraphqlacademy/cloud-run-proxy

I've tested a Cloudflare worker with a proxy in the same region that the Cloud Function and monitored it over the same period.  It was slower than the Cloud Run, although it was 100% reliable.

image

You can use this code if you want to test the Cloudflare worker https://gist.github.com/alexlbr/814446f03cf12e22f07ccaa580eb1154. @wangchou If I'm not mistaken, you could run the Cloudflare worker in Tokio, so it can be closer to the edge where the user is since Cloud Run is not supported yet in that region.

The following monitors the Cloud Function directly without any proxy during the same period.

image

I've used https://uptimerobot.com for the monitoring.

Cloud Run looks very promising to me, I can't wait to the full release

Any updates on this ? Why it's closed ?

Impossible?

@abdellahaski @l2aelba We definitely hear the pain point here. As @mbleigh said earlier, filing it as a feature request (see below) is the best way to help this gain traction for us internally. Thanks!

This issue is closed because it's a feature request for Firebase Hosting that can't be addressed directly in the Firebase CLI. Feature requests are tracked internally and I'd encourage you to request support for additional regions via this form.

We are definitely aware that many of you want this feature, thanks for the feedback!

Would like to see asia-east2 support too.

I'm close to giving up on firebase because of the bad documentation.

An absolute minimum would be to issue a warning if there is no function in us-central matching the function in the redirect!

I suggest the firebase team tries to let someone develop a project where the users are outside the US. It's crazy that we don't get warnings for this kind of stuff.

Lets help each other out by doing as they ask - post a feature request:
https://firebase.google.com/support/troubleshooter/report/features

Here's a draft for you to copy/paste from - just get it done :)

Hosting rewrites to functions in non-US region
https://github.com/firebase/firebase-tools/issues/842

Really need to be able to create rewrites to functions in regions other than US-Central1.

Our target audience is not in US and the lack of this feature is a great painpoint to us, making us uncertain to dedicate our tech-stack to Firebase overall.

Please do consider prioritize this feature in near future.
Thank you,

image

Here hoping for this feature soon!

Has anyone researched into using cloud run instead of cloud functions ?

Cloud run provides functionalities in other regions also

Two years after and this is still a problem.. Why is this closed by the way?

Hi, this is expected behavior, please see https://firebase.google.com/docs/functions/locations#http_and_client_callable_functions, the blue box indicates that all functions that serve as hosting redirects must be in 'us-central1', this is due to the fact that that's where the hosting origin is.

Paging @laurenzlong

Cloud Functions is available in the following regions:

  • us-central1 (Iowa)
  • us-east1 (South Carolina)
  • us-east4 (Northern Virginia)
  • europe-west1 (Belgium)
  • europe-west2 (London)
  • europe-west3 (Frankfurt)
  • asia-east2 (Hong Kong)
  • asia-northeast1 (Tokyo)

I choosed eur3 (europe-west) because it was in top of the list together with us-central1, and separeted from other locations. Thought these two are default.

What should I do , is there any fix on this?

Why?????

Hi folks, thanks for all the feedback on this. We definitely hear you that you'd like to see Firebase Hosting support functions outside of us-central1. Unfortunately there's a significant amount of infrastructure work that has to happen before it would work well, so we can't just "flip a switch" and bring other regions online.

We've heard about this quite often as a feature request, and it's on our roadmap though I can't comment on specific timelines. This repository is not the correct place to post feature requests for the Firebase Hosting product as a whole -- if you are interested in this feature, please submit a feature request so that we can continue to track the interest in this internally and prioritize the work that needs to happen to enable it.

Thanks all!

Hi,

I think noone cares where you host, we want just a simple fix so that error won't show.

This fix can be done in your code, nothing to do where you do your hosting..

And this is not request for a feature, the removal of a bug doesn't become a feature. Just remove that bug

Thanks..

Was this page helpful?
0 / 5 - 0 ratings