如何指定Google Cloud Function的区域? [英] How can I specify the region of a Google Cloud Function?

查看:241
本文介绍了如何指定Google Cloud Function的区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Google Cloud Function构建我的Restful API. 但是,我发现速度很慢,因为我的Google-Cloud-Function服务器位于"us-central"上,而我的服务位于亚洲.

I'm currently using Google Cloud Function to build up my restful API. However, I've found that it's slow because the my Google-Cloud-Function server is on "us-central", whereas my service is in Asia.

我尝试将Google Project的默认区域更改为"asia-west-1"并重新启动云功能-我按照

I tried to change the default region of my Google Project to "asia-west-1" and restart the cloud function—I followed the steps outlined here—but, unfortunately, it's still in "us-central". How can I change the function's region ?

推荐答案

没有"asia-west-1"这样的区域

在Google Cloud Platform上没有"asia-west-1"这样的区域.在撰写本文时, GCP在亚洲提供以下区域:

  • asia-east1
  • asia-northeast1
  • asia-south1
  • asia-southeast1
  • asia-east1
  • asia-northeast1
  • asia-south1
  • asia-southeast1

但是,asia-northeast1当前是亚洲唯一可用于Google Cloud Functions的GCP区域:

However, asia-northeast1 is currently the only GCP region in Asia available for Google Cloud Functions:

$ gcloud functions regions list
NAME
projects/xxxxxxxx/locations/europe-west1
projects/xxxxxxxx/locations/us-east1
projects/xxxxxxxx/locations/us-central1
projects/xxxxxxxx/locations/asia-northeast1

如何指定Google Cloud Function的区域

使用Google Cloud Console

区域设置很容易错过.它实际上隐藏在名为"More"的手风琴后面:

How to specify the region of a Google Cloud Function

Using Google Cloud Console

The region setting is easy to miss. It's actually hidden behind an accordion entitled "More":

点击它会显示一个 Region 下拉列表(在其他高级设置中):

Clicking on it reveals a Region dropdown (among other advanced settings):

使用--region标志仅指定四个可用区域之一.

Simply specify one of the four available regions using the --region flag.

假设您拥有

$ tree .
.
└── index.js

0 directories, 1 file
$ cat index.js 
exports.hello = (req, res) => {

  res.send(`Hello World!`); 

}

然后跑步

gcloud functions deploy hello --region asia-northeast1 --trigger-http

应将功能hello部署到区域asia-northeast1:

这篇关于如何指定Google Cloud Function的区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆