Allow for escaping of variable syntax in `serverless.yml`
See original GitHub issueAllow for escaping of reserved variable characters (i.e. ${…)?
From this forum post http://forum.serverless.com/t/escaping-variable-syntax/1045?u=brianneisler
So suppose I would like to use my/topic/something/${timestamp()} as an S3 object key for writing to an S3 bucket. ${timestamp()} is a valid CloudFormation syntax for referencing IoT SQL functions. However, since this syntax is placed in Serverless file, the framework will look at it as if I’m referencing Serverless timestamp() variable and will obviously return an error below:
Invalid variable reference syntax for variable timestamp(). You can only reference env vars, options, & files. You can check our docs for more info. I tried escaping it with a backslash, but it seems that escaping is then itself escaped as my backslashes are propagated further to the CloudFormation.
We should allow for this type of character escape.
Perhaps a simple approach is \${}
Proposed solution
(Added in later turn by maintainers)
Ideally \${}
and \\\${}
should escape, but \\${}
and \\\\${}
not. That can neatly be achieved by resolving templates via state machine (as one here: https://github.com/medikoo/es6-template-strings/blob/6a7ec2ec4fdf95176f48584e550a81c494c03b1c/compile.js), which should also be intelligent in handling nested variable resolution properly.
- Implement a state machine, through which from every string we can retrieve eventual configured variables
- Apply a
variablesSynteax
regex on resolved variable, to ensure it matches our format, and if it passes resolve further variable as it happens currently
Issue Analytics
- State:
- Created 6 years ago
- Reactions:28
- Comments:21 (6 by maintainers)
Maybe escaping should follow the same pattern as terraform; provide a double dollar sign (
$${}
) option to escape variables that the user expects CloudFormation to parse, and not Serverless?Reference: https://www.terraform.io/docs/configuration/interpolation.html
another workaround would be to escape the ${ part by merging separate parts using the Join function: