Manage Environment Related Config

Link to chapter -

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:


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

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


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:

  - '@cruglobal/serverless-merge-config'

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