adrianTomas
adrianTomas

Reputation: 43

Combine properties in serverless.yml

I have a custom section in serverless.common.yml, which is common to all the services. Some services use some additional properties in their serverless.yml appart from the defined in the file mentioned before.

My idea would be to perform something like:

custom:
  - ${file(../serverless.common.yml):custom}
  - myServiceCustomProperty: 1

But this does not work. Any idea about how can I achieve that behaviour?

Thank you

Upvotes: 3

Views: 1589

Answers (1)

cyberwombat
cyberwombat

Reputation: 40064

- ${file(../serverless.common.yml):custom} is going to dump the array from common so that wont merge. With this approach you need to add each property from the common/custom section individually:

custom:
  - foo: ${file(../serverless.common.yml):custom.foo}
  - myServiceCustomProperty: 1

or

custom: ${file(../serverless.common.yml):custom}

Alternatively if your setup is complex you can write a serverless.js file instead which allows JS processing. I personally use that to programically merge a dozen yml file - for example when I run sls offline I want to add/remove a bunch of stuff so that's a pretty powerful approach.

Upvotes: 2

Related Questions