Reputation: 102587
I read this doc: https://serverless.com/framework/docs/providers/google/guide/services/
users/
serverless.yml # Contains 4 functions that do Users CRUD operations and the Users database
posts/
serverless.yml # Contains 4 functions that do Posts CRUD operations and the Posts database
comments/
serverless.yml # Contains 4 functions that do Comments CRUD operations and the Comments database
how can I combine these serverless.yml
files to single serverless.yml
file? Beside deploy each service, I can run serverless deploy
once to deploy all services too.
Upvotes: 7
Views: 11092
Reputation: 919
I am defining functions in individual serverless.yml files and include file reference under functions in the main serverless.yml file and it works for me, I am also naming individual yml files as posts-sls.yml, users-sls.yml etc.
# foo-functions.yml
getFoo:
handler: handler.foo
deleteFoo:
handler: handler.foo
# serverless.yml
---
functions:
- ${file(../foo-functions.yml)}
- ${file(../bar-functions.yml)}
Referenced here:
https://github.com/serverless/serverless/issues/4218 https://serverless.com/framework/docs/providers/aws/guide/functions/
Upvotes: 20
Reputation: 8482
The easiest way to do this is to use a plugin (like this one: https://github.com/economysizegeek/serverless-dir-config-plugin)
If you want more control, you can also do-it-yourself. For example, you could put the function specific configurations in each directory and then use a tool like cat
to join them with a common one for the project (e.g. cat serverless.common.yml users/serverless.yml posts/serverless.yml comments/serverless.yml > serverless.yml
). Although you may have to write something more complex if you want to merge together keys &c.
Upvotes: 0