Cloud Functions is regional, which means the infrastructure that runs your Cloud Function is located in a specific region and is managed by Google to be redundantly available across all the zones within that region.
When selecting what region to run your Cloud Functions in, your primary considerations should be latency and availability. You can generally select the region closest to your Cloud Function's users, but you should also consider the location of the other GCP products and services that your app uses. Using services across multiple locations can affect your app's latency, as well as pricing.
Cloud Functions is available in the following regions:
You can deploy functions to different regions within a project, but once the region has been selected for a function it cannot be changed.
Functions in a given region in a given project must have unique (case insensitive) names, but functions across regions or across projects can share the same name.
Selecting the region
You can select a region for your function during deployment.
If you are using the
gcloud command-line tool, you can specify the region
by using the
--region flag. For example:
gcloud functions deploy FUNCTION_NAME --region REGION FLAGS...
REGION is one of the regions listed above.
In the above example,
FLAGS... refers to other
arguments that you pass during deployment of your function. For a complete
reference for the
deploy command, see
gcloud functions deploy.
If you are using the GCP Console, you can select the region when you create and deploy a function.
In the GCP Console, go to the Cloud Functions Overview page.
Make sure that the project for which you enabled Cloud Functions is selected.
Click Create Function.
Expand the More menu.
Under Region, select your region.
Best practices for changing region
If you need to change a region where a function is deployed, follow the recommendations below.
For HTTP functions, we recommend that you first redeploy your HTTP function to
the destination region (it can have the same name), and then alter your original
function to redirect its HTTP request to the new function. If clients of your
HTTP function support redirects, you can simply change your original function
to return an HTTP redirect status (
301) along with the URL of your new
function. If your clients do not handle redirects well, you can proxy the
request from the original function to the new function by initiating a new
request from the original function to the new function. The final step is to
ensure that all clients are calling the new function.
Background functions adopt an at-least-once event delivery semantic, which means that under some circumstances they can receive duplicate events, and so should always be implemented to be idempotent. If your function is already idempotent then you can simply redeploy the function in the new region with the same event trigger, and remove the old function after you verify that the new function is correctly receiving traffic. During this transition both functions will receive events.
If your function is not currently idempotent, or its idempotency does not extend beyond the region, then we recommend that you first implement idempotency before moving the function.