Split serverless.yml apigw big events nodes

Hello there,

I was wondering if it was possible to split a serverless.yml file into multiple files.
In particular, I have a fairly large lamba function api gateway. My “events” node is growing very hard and becoming difficult to manage.

I CANT divide the function, for me it is !important that it is only one api service.
Its possible to divide the “events” node of the serverless yml into several files, perhaps for each resource of my api service for example:

users-events.serverless.yml;
posts-events.serverless.yml;
and so on?

I attach my serverless.yml

I hope it is doable.
thank you all.

This is not something I’ve tried but from the documentation (Serverless Variables) it looks like you could do it. Maybe something like:

functions:
  graphql:
    ...
    events:
      ${file(./users-events.serverless.yml):events}
      ${file(./posts-events.serverless.yml):events}

Maybe. Try experimenting with that or something like it.

Dude, thanks for answering me.

It’s something I’ve tried with no success. Unfortunately I do not understand, and the doc does not clarify, how to possibly structure the file in the variable.

My test is:

I think the way the roles file is structured is okay. I believe the problem is how you included it in the parent file. Instead of

events:
  - roles: ${file(./src/serverless/roles.serverless.yml).roles}

try

events:
  ${file(./src/serverless/roles.serverless.yml).roles}

Unfortunately none of the attempts work!

Test 1:


Test 2: