Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to escape $ sign in serverless yaml config?

I want to escape $ sign when using stage variables for api gateway.

Following error appears when I try to deploy.

Invalid variable reference syntax for variable stageVariables.capabilitySecurityUrl. You can only reference env vars, options, & files. You can check our docs for more info.

I have tried following options, but not working

1) Using Without Quotes Uri: https://${stageVariables.capabilitySecurityUrl}

2) Using with quotes Uri: "https://${stageVariables.capabilitySecurityUrl}"

3) Access variable from file

./stageVariables.json
{
   "capabilitySecurityUrl":"https://${stageVariables.capabilitySecurityUrl}"
}

./serverless.yml
${file(./stageVariables.json):capabilitySecurityUrl}

Any help?

like image 715
Jagdish Idhate Avatar asked May 03 '17 16:05

Jagdish Idhate


1 Answers

As author said, customizing variableSyntax worked for me:

  # notice the double quotes for yaml to ignore the escape characters!
  # Use this for allowing CloudFormation Pseudo-Parameters in your serverless.yml
  # e.g. ${stageVariables.my_var}. All other Serverless variables work as usual.
  variableSyntax: "\\${((?!stageVariables)[ ~:a-zA-Z0-9._@'\",\\-\\/\\(\\)]+?)}"

https://www.serverless.com/framework/docs/providers/aws/guide/variables/#using-custom-variable-syntax

like image 66
Xavier Garnier Avatar answered Nov 02 '22 18:11

Xavier Garnier