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

Error when setting custom function name

Open Joe5K opened this issue 5 years ago • 8 comments

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
 

Joe5K avatar Apr 02 '20 07:04 Joe5K

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

Trowsing avatar Apr 17 '20 12:04 Trowsing

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

zxhaaa6 avatar Apr 29 '20 02:04 zxhaaa6

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.

jazarja avatar Apr 30 '20 15:04 jazarja

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
...

gleniosp avatar May 19 '20 16:05 gleniosp

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 avatar Jun 26 '20 08:06 saiaman

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

saiaman avatar Jun 26 '20 08:06 saiaman

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;
};  

m3po-onedollarbill avatar Jun 27 '20 03:06 m3po-onedollarbill

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

functions:
  report_reminder:

to

functions:
  report-reminder:

solved problem

hellysmile avatar Oct 13 '22 08:10 hellysmile