serverless / serverless-google-cloudfunctions

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

Error when setting custom function name #211

Open Joe5K opened 4 years ago

Joe5K commented 4 years ago

Hello,

I want to get rid of service name and stage in function name, but I have a problem setting custom name for function. There is always an error after deployment, it looks like first 2 letters of function are cut off. Did someone resolve this error and could help me solve it? Thanks.

#serverless.yml
...
functions:
  report_reminder:
    name: report_reminder
    handler: report_reminder
    events:
      - http: path
...
$ serverless deploy

Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Compiling function "report_reminder"...
Serverless: Uploading artifacts...
Serverless: Artifacts successfully uploaded...
Serverless: Updating deployment...
Serverless: Checking deployment update progress...
...................................
Serverless: Done...

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

  Function "port_reminder" doesn't exist in this Service

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information ---------------------------
     Operating System:          linux
     Node Version:              8.10.0
     Framework Version:         1.67.0
     Plugin Version:            3.6.0
     SDK Version:               2.3.0
     Components Version:        2.22.3
Trowsing commented 4 years ago

I have the same problem. The function deploys and works correctly though, but it's annoying to have this message all the time.

zxhaaa6 commented 4 years ago

@Joe5K I think you could remove name: report_reminder and try again.

jazarja commented 4 years ago

The problem with removing 'name' is the HTTP endpoint URL will be different from older serverless-google-cloudfunction version (which uses handler name) while the latest version uses function name as HTTP endpoint URL.

GlenioSP commented 4 years ago

Any news about this issue? I don't know why, but it looks like the serverless-google-cloudfunctions looks for a function name with the name we declared, but replacing its first two characters. So @Joe5K, it will possibly remove the errors if you declare your function reference name like this:

#serverless.yml
...
functions:
  port_reminder:
    name: report_reminder
    handler: report_reminder
    events:
      - http: path
...
saiaman commented 4 years ago

the issue is in the const getFunctionNameInService = (funcName, service, stage) function .... if you overwrite function name like me, it's hardcoded that it has to slice name after removing.... so ugly code on my opinion

saiaman commented 4 years ago

for now, be sure the name in properties and the name in the yaml are the same for example :

report_reminder: name: report_reminder

And modify file : info/lib/displayServiceInfos.js change the function getFunctionNameInService with this :

const getFunctionNameInService = (funcName, service, stage) => { let funcNameInService = funcName; if( funcNameInService.indexOf(service)>0 && funcNameInService.indexOf(stage)>0 ){ funcNameInService = funcNameInService.replace(service, ''); funcNameInService = funcNameInService.replace(stage, ''); funcNameInService = funcNameInService.slice(2, funcNameInService.length); } return funcNameInService; };

Should work

m3po-onedollarbill commented 4 years ago

This was very helpful @saiaman

Here is what worked for me:

const getFunctionNameInService = (funcName, service, stage) => {
  let funcNameInService = funcName;
  if( funcNameInService.indexOf(service)>=0 && funcNameInService.indexOf(stage)>=0 ){
    funcNameInService = funcNameInService.replace(service, '');
    funcNameInService = funcNameInService.replace(stage, '');
    funcNameInService = funcNameInService.slice(2, funcNameInService.length);
  } 
  return funcNameInService;
};  
hellysmile commented 1 year ago

I had exactly same issue, changing _ (underscore) to - (dash) eg

functions:
  report_reminder:

to

functions:
  report-reminder:

solved problem