找不到我的入口点?"/>
为什么我的 Cloud Function 找不到我的入口点?
我正在尝试使用打字稿和 ESM 部署 nodejs CloudEvent 云功能。我也在尝试自己在本地构建捆绑包,而不是让 gcp 为我做这件事。我知道这不是推荐的方法,但基于this.
似乎应该是可能的我尝试了 2 种方法,都没有产生有效的 CloudEvent 云功能。
我的
index.ts
长这样:
import * as ff from '@google-cloud/functions-framework';
interface PubSubData {
subscription: string;
message: {
messageId: string;
publishTime: string;
data: string;
attributes?: {[key: string]: string};
};
}
ff.cloudEvent<PubSubData>('myFnName', ce => {
console.log(JSON.stringify(ce));
});
该代码基本上是 this 示例...除了我必须用
import ff
替换 import * as ff
或云功能部署失败与 Provided module can't be loaded. Is there a syntax error in your code?
要创建捆绑包,我使用
esbuild
这样的:esbuild src/index.ts --bundle --platform=node --outdir=dist
输出一个
index.js
,我将其压缩并推入桶中。最后我用部署了函数
gcloud functions deploy my-fn-name --source <my-bundle-bucket-url> --entry-point myFnName --gen2 --runtime nodejs16 --trigger-bucket <my-trigger-bucket-url> --trigger-location us
部署失败
Could not load the function, shutting down.
Did you specify the right function to execute?
Function 'myFnName' is not defined in the provided module.
所以我尝试完全不使用
@google-cloud/functions-framework
包,而是自己定义入口点函数
export const myFnName: (ce: PubSubData) => void = (ce: PubSubData) => {
console.log(JSON.stringify(ce));
};
当我这样做时,函数部署成功,我可以将文件添加到我的触发器桶中,并在部署创建的 PubSub 订阅中看到消息弹出。非常令人兴奋。但是消息从未被确认,云功能也从不记录任何内容。
所以有两个问题: 关于为什么在我使用函数框架注册时云函数找不到我的入口点文件的任何想法? 当我不使用函数框架注册我的入口点函数时,为什么我的云函数忽略 PubSub 消息有什么想法吗?
回答如下:更多推荐
为什么我的 Cloud Function 找不到我的入口点?
发布评论