OperationError 部署 gcloud 函数发布

OperationError deploying gcloud function publish

我正在尝试 运行 通过对 Google Cloud Pub/Sub Triggers 的介绍。当运行宁示例代码:

gcloud functions deploy publish --runtime nodejs8 --trigger-http

我收到以下错误:

ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Function failed on loading user code. Error message: Node.js module defined by file index.js is expected to export function named publish

stackdriver 上的日志显示:

D 2019-11-18T23:53:41.689Z publish Node.js module defined by file index.js is expected to export function named publish  
E 2019-11-18T23:53:41.761Z Cloud Functions CreateFunction us-central1:publish <email> INVALID_ARGUMENT Cloud Functions CreateFunction us-central1:publish <email> 
E 2019-11-18T23:54:15.667Z Cloud Functions UpdateFunction us-central1:publish <email> FAILED_PRECONDITION Cloud Functions UpdateFunction us-central1:publish <email> 

原来我试图从错误的目录进行部署。正确的 index.js 文件包含函数定义,并允许成功部署该函数。