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

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

问题描述

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

我尝试将我的 Google 项目的默认区域更改为asia-west-1"并重新启动云功能 - 我按照概述的步骤操作

点击它会显示一个Region下拉菜单(以及其他高级设置):

使用 gcloud

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

最小工作示例

假设你有

$ 树..└── index.js0 个目录,1 个文件$猫 index.jsexport.hello = (req, res) =>{res.send(`你好世界!`);}

然后运行

gcloud 函数部署 hello --region asia-northeast1 --trigger-http

应该将函数hello部署到区域asia-northeast1:

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.

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 ?

解决方案

No such region as "asia-west-1"

There is no such region as "asia-west-1" on the Google Cloud Platform. At the time of writing, GCP provides the following regions in Asia:

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

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

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":

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

Using gcloud

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

Minimal working example

Under the assumption that you have

$ tree .
.
└── index.js

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

  res.send(`Hello World!`); 

}

then running

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

should deploy function hello to region asia-northeast1:

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

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