How can I split up my serverless.yml file into multiple files?
Asked Answered
C

4

7

I am using the Serverless Framework for my AWS-powered application. I've been writing a super-long serverless.yml file so far, which contains all my lambda code, resources, IAM roles, and State Machines. T find it very hard to manage this big file. How can I work around this? Is there any way to split my serverless.yml file into smaller, manageable chunks? It'd be awesome if I can get one yml per lambda. Thanks in advance

Campanology answered 7/5, 2021 at 11:14 Comment(0)
C
6

After a lot of Googling, I've finally found something useful!

https://www.serverless.com/blog/structuring-a-real-world-serverless-app

Campanology answered 7/5, 2021 at 13:3 Comment(0)
S
1

You can have one file per lambda, just follow the official serverless docs, scroll down to the word "separate" (or, here is my copy-paste , docs from 2024):

# serverless.yml
---
functions:
  - ${file(./foo-functions.yml)}
  - ${file(./bar-functions.yml)}

and "lambda" file:

    
# foo-functions.yml
getFoo:
  handler: handler.foo
deleteFoo:
  handler: handler.foo
Steiermark answered 4/3 at 4:25 Comment(0)
C
0

I've been looking for this on google and found this post. Also I find a youtube video that explain really well how to split a serverless file.

Split Serverless Files

I hope it really helps to someone who looks for this in the future.

Cynical answered 15/6, 2023 at 16:26 Comment(3)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Rugging
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From ReviewMortarboard
be careful - the link is a 10min youtube video (I didn't expect it here). Please, share the answer after watching it, thanks!Steiermark
B
-1

I think that you could separate your project into services. Then, inside of each service, you can define one serverless.yml. You can see the best explanation here:

Serverless Framework - Documentation: Services

Burmaburman answered 23/12, 2021 at 18:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.