How can I specify the region of a Google Cloud Function?

前端 未结 3 1291
梦谈多话
梦谈多话 2021-01-13 16:36

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\",

3条回答
  •  孤街浪徒
    2021-01-13 17:22

    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:

提交回复
热议问题