Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring resources in multiple files in Serverless framework

Is there any way to split the resource definitions in serverless framework into multiple files? Something like:

resources:
  - ${resources/base.yml}
  - ${resources/foo.yml}

I have been trying multiple combinations but I keep getting errors about references not being found.

like image 816
Jesuspc Avatar asked Dec 15 '17 13:12

Jesuspc


2 Answers

Even though dashmug's answer is correct, I found that the way I was trying to make it work was quite close to a valid solution too. As explained in this github comment it is possible to reference other files in the resources section:

resources:
   - ${file(resources/first-cf-resources.yml)}
   - ${file(resources/second-cf-resources.yml)}

Provided that each those files defines a "Resources" key of its own, like:

---
Resources:
  MyCFResource:
    Type:.....

What I didn't manage is to have a mixed approach such as:

resources:
  - ${file(resources/first-cf-resources.yml)}
  - ${file(resources/second-cf-resources.yml)}
  SomeResource:
    Type: ...

So I just have a resources/base.yml for that instead.

like image 185
Jesuspc Avatar answered Oct 05 '22 05:10

Jesuspc


I can't comment but I'd like to extend Jesuspc's answer.

There is a way to achieve that 'mixed' approach, in serverless.yml:

resources:
  - ${file(resources/first-cf-resources.yml)}
  - ${file(resources/second-cf-resources.yml)}
  - Resources:
      SomeResource:
        Type: ...

In this case files first-cf-resources.yml and second-cf-resources.yml must have the next structure:

Resources:
  SomeResourceA:
    ...
  AnotherResourceB:
    ...
like image 41
Niv-Mizzet Avatar answered Oct 05 '22 05:10

Niv-Mizzet