New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for escaping of variable syntax in serverless.yml
#3565
Comments
Interesting! We have the possibility to define an own Here's an example on how to use it: #3561 (comment) Could this potentially be used to mitigate this problem? |
@pmuens, i think it can but as the forum post points out that's a bit extreme for something so simple. Seems convenient to offer a simple escape mechanism. |
Yeah, I kinda need to escape |
Note that the workaround ( |
Note that this workaround didn't work if you resolve nested variables like this:
To be able to do this you need to use this variableSyntax:
This is copied from official documentation (https://serverless.com/framework/docs/providers/aws/guide/variables#using-custom-variable-syntax). And because I'm already writing comment: Escaping like this |
another workaround would be to escape the ${ part by merging separate parts using the Join function:
|
+1 As I set partition key for IoT Topic Rule (Kinesis Action), I want to put "${topic()}" value.
does't work (as expected). So I used ernieay's workaround.
But it could be simpler. |
Maybe escaping should follow the same pattern as terraform; provide a double dollar sign (
Reference: https://www.terraform.io/docs/configuration/interpolation.html |
For my use case, I need to be able to escape curly brackets that appear in paths when importing files via This breaks...
Ideally I would like to use something like backslash to escape the special characters...
|
I too am trying to include ${aws:username} in a resource definition for a s3 policy in order to permit access to s3 buckets which match the username. It would be nice to be able to pass a literal without interpolation. |
@kbsanders any luck ?
|
@FreddyJD No, I ended up using a different character (underscores) to represent path variables.
It's been a while since I've worked on the project where this code is used though, so I don't know if any improvements have been made to allow escaping curly brackets or not in serverless config files. |
Any update on this? I need it too +1 |
I just hit this myself, it's a frustrating issue for people who need to pass a literal into cloud formation configuration. |
Passing literals into cloud formation is something that you do quite often. |
I use the serverless-cloudformation-sub-variables plugin then you can use things like The plugin converts |
I believe main use case was to address collision with AWS variables syntax (#3184), and that was already solved through improved regular expression. Still I believe for completeness there should be some escape mechanism respected, I've outlined in main description a proposal on how we can achieve that |
Closing, as escaping is supported by a new resolver, e.g |
I've a variable I've tried using |
@dhruvsaxena1998 if you feel that escape mechanism doesn't work, firstly please ensure you're on latest version of a Framework, and if it confirms to be the case there, please open a bug report, documenting a minimal reproducible case that doesn't involve plugins. |
I have noticed that I had to sometimes double escape with |
Allow for escaping of reserved variable characters (i.e. ${...)?
From this forum post http://forum.serverless.com/t/escaping-variable-syntax/1045?u=brianneisler
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.variablesSynteax
regex on resolved variable, to ensure it matches our format, and if it passes resolve further variable as it happens currentlyThe text was updated successfully, but these errors were encountered: