Dum*_*ius 4 latency region google-cloud-platform gcloud google-cloud-functions
我目前正在使用Google Cloud Function来构建我的restful API.但是,我发现它很慢,因为我的Google-Cloud-Function服务器位于"us-central",而我的服务是在亚洲.
我尝试将我的Google项目的默认区域更改为"asia-west-1"并重新启动云功能 - 我按照此处列出的步骤进行了操作- 但不幸的是,它仍处于"us-central"状态.如何更改功能区域?
小智 6
Google Cloud Functions目前似乎仅在us-central1区域提供.如果我转到"创建功能"(https://console.cloud.google.com/functions/add),"区域"下拉列表只有一个选项,它是us-central1.
Google Cloud Platform 上没有“asia-west-1”这样的区域。在撰写本文时,GCP 在亚洲提供以下区域:
asia-east1asia-northeast1asia-south1asia-southeast1但是,asia-northeast1目前是亚洲唯一可用于 Google Cloud Functions 的 GCP 区域:
$ 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
Run Code Online (Sandbox Code Playgroud)
区域设置很容易错过。它实际上隐藏在名为“更多”的手风琴后面:
单击它会显示区域下拉列表(以及其他高级设置):
gcloud只需使用--region标志指定四个可用区域之一。
在假设你有
$ tree .
.
??? index.js
0 directories, 1 file
$ cat index.js
exports.hello = (req, res) => {
res.send(`Hello World!`);
}
Run Code Online (Sandbox Code Playgroud)
然后运行
gcloud functions deploy hello --region asia-northeast1 --trigger-http
Run Code Online (Sandbox Code Playgroud)
应该将功能部署hello到区域asia-northeast1:
如果您使用的是 Firebase SDK:
取自文档 - https://firebase.google.com/docs/functions/manage-functions#modify
// before
const functions = require('firebase-functions');
exports.webhook = functions
.https.onRequest((req, res) => {
res.send("Hello");
});
// after
const functions = require('firebase-functions');
exports.webhookAsia = functions
.region('asia-northeast1')
.https.onRequest((req, res) => {
res.send("Hello");
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1969 次 |
| 最近记录: |