Calculated Variables

I need to calculate a variable based on another variable defined in the serverless.yml.

In my particular case I’m setting a Cloudwatch alarm threshold based on a value defined for a service. Is it possible to use serverless variables so I can compute the value for the CloudWatch alarm?

Currently, no. The variables system is not “just” JavaScript.

There are two ways I can think of that you could do this, neither are particularly elegant:

  • Include a JS file (via the variables system) and do the calculation in there. Unfortunately you’d have to do something a bit crazy like read your serverless.yml file (to get the source value) and then return the calculated output.
  • Use CloudFormation mappings to work out the calculated value. This would only be practical if there was a limited number of potential values.