9

I'd like to deploy the same cloud function(s) across multiple regions. Is there an easy way to do it?

2 Answers 2

8

Since you haven't said what type of function you want to deploy, I'll assume https function. It doesn't make sense to deploy any other type of (background) function to multiple regions, as each may trigger for each event, which would be fairly chaotic. With https functions, you'll have a different URL for each one

You can deploy two different functions with the same implementation to different regions:

function f(req, res) {
    // your https function implementation here
}

exports.f_asia_northeast1 = functions
    .region('asia-northeast1')
    .https.onRequest(f);

exports.f_us_central1 = functions
    .region('us-central1')
    .https.onRequest(f);
Sign up to request clarification or add additional context in comments.

5 Comments

"as each may trigger for each event" - so, it's nondeterministic? I'd like to have a definitive answer whether a function in multiple regions will be triggered in all regions, or one.
You should expect that it will be triggered in multiple regions.
@DougStevenson . I'd like to deploy my HTTPS functions across several regions and invoke them according to the location of the visitor of my app. Do you guys plan to add a regional load balancer for the HTTPS functions? A kind of Anycast DNS on top of Cloud Functions would be great!
@Antonio I don't know of anything like that. But if you have a feature request, please log it here: firebase.google.com/support/contact/bugs-features
Can they somehow have the same name? So that all that the clients will need to change will be the region, not the function name.
1

I haven't tried it yet, but the docs say:

You can specify multiple regions by passing multiple comma-separated region strings in functions.region().

Hence, something like

function f(req, res) {
    // your https function implementation here
}

exports.thefunction = functions
    .region('asia-northeast1', 'us-central1')
    .https.onRequest(f);

should work both for deploying the same function across multiple regions and for assigning the same (unique) name to all the "copies".

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.