serverless-google-cloudfunctions icon indicating copy to clipboard operation
serverless-google-cloudfunctions copied to clipboard

Function "1-first" doesn't exist in this Service

Open emmeblm opened this issue 8 years ago • 3 comments

When I try to deploy a function called "first" (this is how it is called in the serveless.yml file), the deployment goes well but after seeing the message: Serverless: Done... I get the following error:

SLS_DEBUG=* serverless deploy --environment dev01 --project <MyProjectID>
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Compiling function "first"...
Serverless: Creating deployment...
Serverless: Checking deployment create progress...
..
Serverless: Done...
Serverless: Uploading artifacts...
Serverless: Artifacts successfully uploaded...
Serverless: Updating deployment...
Serverless: Checking deployment update progress...
........
Serverless: Done...

  Serverless Error ---------------------------------------

  Function "1-first" doesn't exist in this Service

  Stack Trace --------------------------------------------

ServerlessError: Function "1-first" doesn't exist in this Service
    at Service.getFunction (/Users/xxx/.nvm/versions/node/v6.11.1/lib/node_modules/serverless/lib/classes/Service.js:195:11)
    at _.forEach (/Users/xxx/node_modules/serverless-google-cloudfunctions/info/lib/displayServiceInfo.js:43:53)
    at arrayEach (/Users/xxx/node_modules/lodash/lodash.js:537:11)
    at Function.forEach (/Users/xxx/node_modules/lodash/lodash.js:9359:14)
    at GoogleInfo.gatherData (/Users/xxx/node_modules/serverless-google-cloudfunctions/info/lib/displayServiceInfo.js:39:7)
From previous event:
    at PluginManager.invoke (/Users/xxx/.nvm/versions/node/v6.11.1/lib/node_modules/serverless/lib/classes/PluginManager.js:242:22)
    at PluginManager.run (/Users/xxx/.nvm/versions/node/v6.11.1/lib/node_modules/serverless/lib/classes/PluginManager.js:261:17)
    at variables.populateService.then (/Users/xxx/.nvm/versions/node/v6.11.1/lib/node_modules/serverless/lib/Serverless.js:99:33)
    at runCallback (timers.js:672:20)
    at tryOnImmediate (timers.js:645:5)
    at processImmediate [as _immediateCallback] (timers.js:617:5)
From previous event:
    at Serverless.run (/Users/xxx/.nvm/versions/node/v6.11.1/lib/node_modules/serverless/lib/Serverless.js:86:74)
    at serverless.init.then (/Users/xxx/.nvm/versions/node/v6.11.1/lib/node_modules/serverless/bin/serverless:39:50)

I can see that somewhere, it's adding a "1-" string to the name. Not sure if it's the plugin code or not.

Any ideas?

Thanks!

emmeblm avatar Aug 28 '17 21:08 emmeblm

So I found the problem. It's actually in the info/lib/displayServiceInfo.js file.

The stage variable in the serverless.yml is something that should be able to have any value on it (in my case I used dev01 as it is our standard in our project). But in this file, in line 32, you are taking the stage from this.options.stage instead of taking the value from this.serverless.service.provider.stage. The same happens at line 41 (in the same file), where you are calling the function getFunctionNameInService and passing the this.options.stage on it instead of the one defined in the serverless.yml file.

So this is a bug when you use a stage different from dev.

Changing those things directly in my local machine I was able to get the correct output from serverless:

SLS_DEBUG=* serverless deploy --environment dev01 --project myProject
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Compiling function "first"...
Serverless: Uploading artifacts...
Serverless: Artifacts successfully uploaded...
Serverless: Updating deployment...
Serverless: Checking deployment update progress...
......
Serverless: Done...
Service Information
service: myService
project: myProject
stage: dev01
region: us-central1

Deployed functions
first
  https://us-central1-myProject.cloudfunctions.net/http

Serverless: Removing old artifacts...

Can I submit a pull request fixing this? Or could you fix it directly?

Best regards

emmeblm avatar Aug 28 '17 22:08 emmeblm

Closing this issue as found out the best way to change the stage on serverless is using the --stage on the serverless deploy command and not by defining it in the serverless.yml (Although the code of aws does support the stage being defined in the serverless.yml file).

emmeblm avatar Aug 28 '17 23:08 emmeblm

Thanks for opening @emmeblm 👍

That's a nice catch! I'll re-open this one since the Google Cloud Functions plugin should support this as well!

pmuens avatar Aug 29 '17 08:08 pmuens