You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Overwriting variable resolution require string fallbacks to be fully resolvable #7435
1. What did you do?
In my serverless.yaml I declare a variable with this syntax: ${env:SomeUrl, "${cf:my-stack.ServiceEndpoint}/api"}.
My intent is to use the cloudformation resolution (which only gives part of url) in most cases. But in some cases I want to override the URL by a sysenv variable. For example when there is no "my-stack" deployed.
But if I set env variable SomeUrl and my-stack is not deployed deployed, it fails :-(
2. What happened?
ServerlessError: Stack with id my-stack does not exist
3. What should've happened?
The resolver should succeed by just successfully resolve env:SomeUrl. Because the second part is only some kind of fallback it is of no interest if the first part is resolvable.
4. What's the content of your serverless.yml file?
5. What's the output you get when you use the SLS_DEBUG=* environment variable (e.g. SLS_DEBUG=* serverless deploy)
I call SLS_DEBUG=* SomeUrl=http://localhost/foo sls package
The output is
[...]
Serverless: [AWS cloudformation 400 0.267s 0 retries] describeStacks({ StackName: 'my-stack' })
Serverless Error ---------------------------------------
ServerlessError: Stack with id my-stack does not exist
at C:\Users\xyz\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\provider\awsProvider.js:329:27
at processTicksAndRejections (internal/process/task_queues.js:97:5)
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information ---------------------------
Operating System: win32
Node Version: 12.16.1
Framework Version: 1.65.0
Plugin Version: 3.4.1
SDK Version: 2.3.0
Components Version: 2.22.3
changed the title [-]Overwriting variable resolution require valid fallbacks[/-][+]Overwriting variable resolution require string fallbacks to be fully resolvable[/+]on Mar 7, 2020
@sschulze I agree, ideally fallback should be resolved only when we fallback to it. It might be an issue in design of variable resolver. We're open for PR that improves that.
I'm adding @erikerikson to the discussion, as he has very good understanding of variable resolution mechanism in the Framework, and may provide a valuable insight.
Hmm... Nothing great to say off hand. I'd guess the regex is picking up the inner variable in the string before noticing the outer variable and therefore is unaware of the outer fallback context. Without thinking too much, this may be a limit of the current implementation strategy. There was some code that identified these things separately and there may have been a regression but I can't be certain without taking a look.
Given we have Env variable SomeUrl=http://localhost/foo The Steps followed to resolve the variable with default you provided ${env:SomeUrl, "${cf:my-stack.ServiceEndpoint}/api"} are as follows:
Use Variable Syntax regex \${([^{}]+?)} to extract first variable to resolve, which detects the most inner part of nested vars as it excludes the curly brackets }{. ${cf:my-stack.ServiceEndpoint}
Render the value of the resolved variable. ${env:SomeUrl, "http://example.com/api"}
Run detection again. ${env:SomeUrl, "http://example.com/api"}
Split on comma that is not inside quotes. env:SomeUrl
Resolve
Replace
Decide
Not sure if the process can be reversed though without a huge refactor. I have hard time following all the paths.
Not sure if the process can be reversed though without a huge refactor. I have hard time following all the paths.
I totally agree. It's very hard to solve without rethinking (and probably rewriting) whole variable resolution strategy.
I think it should be solved together with refactor proposed here: #7207
Activity
[-]Overwriting variable resolution require valid options[/-][+]Overwriting variable resolution require valid fallbacks[/+][-]Overwriting variable resolution require valid fallbacks[/-][+]Overwriting variable resolution require string fallbacks to be fully resolvable[/+]medikoo commentedon Mar 7, 2020
@sschulze I agree, ideally fallback should be resolved only when we fallback to it. It might be an issue in design of variable resolver. We're open for PR that improves that.
I'm adding @erikerikson to the discussion, as he has very good understanding of variable resolution mechanism in the Framework, and may provide a valuable insight.
erikerikson commentedon Mar 7, 2020
Hmm... Nothing great to say off hand. I'd guess the regex is picking up the inner variable in the string before noticing the outer variable and therefore is unaware of the outer fallback context. Without thinking too much, this may be a limit of the current implementation strategy. There was some code that identified these things separately and there may have been a regression but I can't be certain without taking a look.
AhmedFat7y commentedon May 14, 2020
Given we have Env variable
SomeUrl=http://localhost/fooThe Steps followed to resolve the variable with default you provided ${env:SomeUrl, "${cf:my-stack.ServiceEndpoint}/api"} are as follows:\${([^{}]+?)}to extract first variable to resolve, which detects the most inner part of nested vars as it excludes the curly brackets}{.${cf:my-stack.ServiceEndpoint}${env:SomeUrl, "http://example.com/api"}${env:SomeUrl, "http://example.com/api"}env:SomeUrlNot sure if the process can be reversed though without a huge refactor. I have hard time following all the paths.
medikoo commentedon May 14, 2020
I totally agree. It's very hard to solve without rethinking (and probably rewriting) whole variable resolution strategy.
I think it should be solved together with refactor proposed here: #7207
medikoo commentedon Apr 12, 2021
Closing as it's works as proposed with new variables resolver, which was shipped recently