使用NodeJS时更改云功能区域

时间:2020-04-19 17:02:02

标签: google-cloud-firestore google-cloud-functions

所以我知道这个问题已经问了很多,常见的答案是添加这样一个区域:

export.webhookEurope = functions
.region('europe-west1')
.https.onRequest((req, res) => {
    res.send("Hello");
});

但就我而言,我正在使用 onCreate 方法,并且在函数中对以上代码进行采样只会引发错误。代码看起来像这样。

export const onCreate = functions.firestore
.document('parent/{id}')
.region('europe-west1')
.onCreate(async (snapshot, context) => {
    // some code which deploys correctly if I leave out the 'region'    
});

因此,在不使用“区域”部分的情况下进行部署可以很好地工作,但是如果我将其保留下来,则会出现以下错误:

npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! functions@ build: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the functions@ build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Error: functions predeploy error: Command terminated with non-zero exit code2

那么更改默认区域的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

您将呼叫region()放在构建器的错误部分。它先于您要触发的产品的标识:

export const onCreate = functions
.region('europe-west1')
.firestore
.document('parent/{id}')
.onCreate(async (snapshot, context) => {
    // some code which deploys correctly if I leave out the 'region'    
});

API reference将来可能会有所帮助。尤其是FunctionBuilder

相关问题