When using multiple service folders, what should a service's serverless.yml look like for google?

google

#1

I’ve created a new service folder with: sls create --template google-nodejs —path customers.

This created a folder called customers/ with 3 files in it: index.js, package.json, & serverless.yml.

Now I’m editing customers/serverless.yml and i’m just curious as to proper formatting for multiple functions (CRUD-like).

I found a couple different formats out in the wild, and have read the docs, but I’m having trouble. Can someone tell me what’s wrong with the following, I keep getting Deployment failed: RESOURCE ERROR - Name in request must be equal to the name of the function. Here are the relevant lines from customers/serverless.yml:

functions:
  create:
    handler: create
    events:
      - http:
        path: customers
        method: post
  list:
    handler: list
    events:
      - http:
        path: customers
        method: get

#2

Looks like the path to your code is incomplete.

Change create to index.create in the handler prop. (do the same for all the functions.)

functions:
  create:
    handler: index.create
    events:
      - http:
        path: customers
        method: post

This should fix your issue


#3

That gives me the following:

Error: The "handler" property for the function "hello" is invalid. 
Handlers should be plain strings referencing only the exported function name without characters such as "." or "/" (so e.g. "http" instead of "index.http"). 
Do you want to nest your functions code in a subdirectory?
Google solves this by utilizing the "main" config in the projects package.json file. Please check the docs for more info.

Regardless, I have since tried about every permutation of that snippet imaginable. And the only way I can get it to run is with the default that is created from the google-nodejs template and a function named http. I would LOVE for you guys to create an example working repo for google that has multiple services/folders as one might use to break out CRUD functionality by “model”.


#4

It’s really unclear error message. But the issue is that function and handler names should not be the same. So, in your example valid config could look like this:

functions:
  createFunction:
    handler: create
    events:
      - http:
        path: customers
        method: post
  listFunction:
    handler: list
    events:
      - http:
        path: customers
        method: get