问题描述
我目前正在使用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的区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!