Manage Environment Related Config

Link to chapter - https://serverless-stack.com/chapters/manage-environment-related-config.html

Is there a way to combine fields from multiple serverless.yml files?

Using this chapter as an example, we have a serverless.common.yml file with a custom field that we we import into the other services:

serverless.common.yml

custom:
  stage: ${opt:stage, self:provider.stage}
  resourcesStages:
    prod: prod
    dev: dev
  resourcesStage: ${self:custom.resourcesStages.${self:custom.stage}, self:custom.resourcesStages.dev}

we later import the custom variable in another serverless.yml file:

serverless.service1.yml

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

What if I want to import the custom variable from serverless.common.yml and define my own custom variables at the same time? Something like:

custom: ${file(../../serverless.common.yml):custom}
  my_custom_field: my_custom_value  # <-- this doesn't work

in my particular use case, I’m trying to use the serverless domain manager plugin to define custom domains for each of my services. I still want serverless.common.yml fields in each of my serverless.yml files, but I also need to add a custom field for the custom domain names.

Yeah there is a plugin that can help with this:

It’ll look something like this:

plugins:
  - '@cruglobal/serverless-merge-config'

custom:
  $<<: ${file(../../serverless.common.yml):custom}
  my_custom_field: my_custom_value
1 Like