Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to combine multiple serverless.yml files to single serverless.yml file?

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.

like image 648
slideshowp2 Avatar asked Oct 09 '18 09:10

slideshowp2


People also ask

What is service in serverless yml function grouping?

The service is simply the name of your project. Since Serverless lets us deploy a project in multiple stages (prod, dev, staging…), CloudFormation stacks will contain both the service name and the stage: app-prod , app-dev , etc.

Which one of the following option will not be taken care of by serverless Yaml?

Explanation: Serverless. yml will not take care of Business logic specification .


1 Answers

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/

like image 92
Khuram Niaz Avatar answered Jan 02 '23 20:01

Khuram Niaz