Add multiple properties to serverless.yaml with one line?

Viewed 230

We have many serverless services. Many of them share some properties. Here is a subset of what they share:

// shared.yaml

frameworkVersion: '3'
configValidationMode: error

plugins:
  modules:
    - serverless-prune-plugin
    - serverless-deployment-bucket

custom:
  sharedHost: ${file(./shared-host.config.js)}
  prune:
    automatic: true
    number: 2

  Outputs:
    UserInformation:
      Value: ${self:custom.sharedHost.userId}
      Description: ${self:custom.sharedHost.userArn}

    GitInformation:
      Value: ${self:custom.sharedHost.gitId}
      Description: ${self:custom.sharedHost.gitDescription}

Is it possible to add these properties to a serverless.yaml file with one line?

I'm looking for something like:

// services/some-service/serverless.yaml

service: SomeService
join: ${file(../../shared.yaml)}

custom:
  someProp: someValue

I'm adding a json tag to the question because I am thinking that if this is not possible using serverless or yaml features, then maybe there is some json feature that could be used.

1 Answers

I know that in serverless.yml file you can import env variables from a external file in one line like this

environment: ${file(env.yml):${self:provider.stage}, file(env.yml):default}

After if you use node js you can have a serverless.ts or serverless.js and import files very easily with Object.assign

resources: {
    Resources: Object.assign(dynamodbTables, gatewayDomain, gatewayAuthorizer),
  }

exemple : https://github.com/TheSmartMonkey/serverless/blob/main/reports-service/serverless.ts

Related