I am attempting to run through the introduction to Google Cloud Pub/Sub Triggers. When running the example code:
gcloud functions deploy publish --runtime nodejs8 --trigger-http
I get the following error:
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
The logs on stackdriver show:
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>
Turns out I was attempting to deploy from the wrong directory. The correct index.js file included the function definition, and allowed successful deployment of the function.