serverless / serverless-google-cloudfunctions

Serverless Google Cloud Functions Plugin – Adds Google Cloud Functions support to the Serverless Framework
https://www.serverless.com
MIT License
271 stars 127 forks source link

'serverless invoke' failed on google cloud function #213

Closed beam36 closed 4 years ago

beam36 commented 4 years ago

Bug Report

 Operating System:          darwin
 Node Version:              13.9.0
 Framework Version:         1.67.3
 Plugin Version:            3.6.6
 SDK Version:               2.3.0
 Components Version:        2.29.1

Description

When following the cloud tutorial https://serverless.com/framework/docs/providers/google/guide/quick-start/, everything works fine until 'invoke' step. I got the below error

  Error: Function http in region us-central1 in project serverless-273703 does not exist
      at Gaxios._request (/Users/beam/Codes/learn/serverless-framework/my-service/node_modules/gaxios/src/gaxios.ts:109:15)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
      at JWT.requestAsync (/Users/beam/Codes/learn/serverless-framework/my-service/node_modules/google-auth-library/build/src/auth/oauth2client.js:350:18)

I've checked that the cloud function got deployed and can be triggered via a browser. Here is serverless.yml

service: my-service

provider:
  name: google
  stage: dev
  runtime: nodejs8
  region: us-central1
  project: serverless-273703
  credentials: ~/.gcloud/keyfile.json

plugins:
  - serverless-google-cloudfunctions

package:
  exclude:
    - node_modules/**
    - .gitignore
    - .git/**

functions:
  first:
    handler: http
    events:
      - http: path

Here's an error after turning on SLS_DEBUG

  Error: Function http in region us-central1 in project serverless-273703 does not exist
      at Gaxios._request (/Users/beam/Codes/learn/serverless-framework/my-service/node_modules/gaxios/src/gaxios.ts:109:15)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
      at JWT.requestAsync (/Users/beam/Codes/learn/serverless-framework/my-service/node_modules/google-auth-library/build/src/auth/oauth2client.js:350:18)
  From previous event:
      at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:490:22)
      at /usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:525:24
  From previous event:
      at PluginManager.run (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:525:8)
      at /usr/local/lib/node_modules/serverless/lib/Serverless.js:133:33
      at processImmediate (internal/timers.js:456:21)
      at process.topLevelDomainCallback (domain.js:137:15)
  From previous event:
      at Serverless.run (/usr/local/lib/node_modules/serverless/lib/Serverless.js:120:74)
      at /usr/local/lib/node_modules/serverless/bin/serverless.js:82:30
      at /usr/local/lib/node_modules/serverless/node_modules/graceful-fs/graceful-fs.js:136:16
      at /usr/local/lib/node_modules/serverless/node_modules/graceful-fs/graceful-fs.js:57:14
      at FSReqCallback.oncomplete (fs.js:158:23)
  From previous event:
      at /usr/local/lib/node_modules/serverless/bin/serverless.js:82:8
      at processImmediate (internal/timers.js:456:21)
      at process.topLevelDomainCallback (domain.js:137:15)
  From previous event:
      at Object.<anonymous> (/usr/local/lib/node_modules/serverless/bin/serverless.js:71:4)
      at Module._compile (internal/modules/cjs/loader.js:1151:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
      at Module.load (internal/modules/cjs/loader.js:1000:32)
      at Function.Module._load (internal/modules/cjs/loader.js:899:14)
      at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
      at internal/main/run_main_module.js:17:47

What did I do wrong?

zxhaaa6 commented 4 years ago

@beam36 can you please confirm the function http exists as an export in index.js?

beam36 commented 4 years ago

@zxhaaa6 Yes, it does. Here's my index.js.

'use strict';

exports.http = (request, response) => {
  response.status(200).send('Hello World!');
};

exports.event = (event, callback) => {
  callback();
};
scastiel commented 4 years ago

I have the same problem. I noticed I was able to invoke my function (after deployment) by changing its name in the serverless.yml file:

service: hello-serverless
# ...
functions:
  hello-serverless-dev-hello: # instead of hello
    handler: hello-serverless-dev-hello # instead of hello
    events:
      - http: path

Obviously not a true solution since I cannot redeploy my function without rolling back the function name. But I guess it shows the issue is with the name of the function called when using serverless invoke