![](/img/trans.png)
[英]use region other than us-central1 for Google Cloud Functions
[英]"ERROR: (gcloud.functions.call) ResponseError: status=[404], code=[Ok], message=[Function XYZ in region us-central1 in project ABC does not exist]"
我正在測試雲 function。
當我從“測試”選項卡在線運行它時,我將 json 字典作為參數粘貼到“觸發事件”編輯器中作為雲 function 的請求變量傳遞為:
{"api_key":"MY_API_KEY"}
(將 MY_API_KEY 替換為純文本密鑰)然后 function 運行。
從 bash 開始,使用gcloud
代替,相同的 function 失敗:
gcloud functions call MY_CLOUD_FUNCTION --data '{"api_key":"$API_KEY"}'
gcloud functions call MY_CLOUD_FUNCTION --data '{"api_key":"$API_KEY"}' ERROR: (gcloud.functions.call) ResponseError: status=[404], code=[Ok], message=[Function MY_CLOUD_FUNCTION in region us-central1 in project MY_CLOUD_PROJECT does not exist]
這很可能不是觸發事件的問題,它恰好是 args 的一部分,但不應該在這里發揮作用。 這是不同地區的問題。 gcloud
需要默認區域us-central1
而我的 function 是europe-west3
(來自“詳細信息”選項卡)。
如何告訴gcloud
使用 function 的區域,而不是默認區域? 或者還有什么方法可以解決這個問題?
gcloud
假定默認值(可以使用gcloud config
獲取|設置)
在這種情況下,您應該在命令中添加標志--region=europe-west3
以指定預期區域,即:
REGION="europe-west3"
gcloud functions call your-function \
--region=${REGION} \
--data="{\"api_key\":\"${API_KEY}\"}"
您可以通過以下方式驗證此行為(希望如此):
gcloud config list
[core]
account = your@email.com
Your active configuration is: [default]
注意上述命令不包括
functions/region
; 我懷疑這是因為us-central1
是默認 (.) 默認值。
gcloud config get-value functions/region
us-central1
我不鼓勵將全局 state 存儲在gcloud config
中(部分原因是它會導致這種類型的混淆)但是,您也可以:
gcloud config set functions/region europe-west3
Updated property [functions/region].
gcloud config get-value functions/region
europe-west3
gcloud functions call your-function \
--data="{\"api_key\":\"${API_KEY}\"}"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.