Repository navigation
Conversation
There was a problem hiding this comment.
Hmm. I personally like this but I'm not entirely sure of the implications. I always use ${opt:stage, self:provider.stage} to avoid the issue and often add a shortcut in custom so that I can use ${self:custom.stage} instead:
custom:
stage: ${opt:stage, self:provider.stage}|
Hi @dschep . But @bvanderlugt found a bug when user does not know/use this approach. |
There was a problem hiding this comment.
Thanks for working on this fix @vkkis93! 👍
🤔 I see the value but I'm also unsure whether we want to introduce the stage concept in lib/Serverless.js (although stages are a first-class citizen).
Also not entirely sure about the implications of this change (especially not when using Serverless in a non-AWS context).
There was a problem hiding this comment.
Just looked into this again today. Is there any way we could bake this into the Variables system? I see the value here and it seems like this is an all to common mistake user usually make.
Generaally speaking ${self:} should reference only values which are present in serverless.yml, so if e.g. there's no foo then ${self:foo} should be undefined but given that we're mixing serverless.yml and it's Serverless Variables system with the internal Serverless object we pass around it becomes unpredictable and hard to understand when working with it.
Edit: I think the best way would be to use defaults here. Defaults are the exact use-case for the desired outcome.
Tweaking ${self:} to do some magic would make it unpredictable. Varaibles which are not defined but referenced via ${self:} in serverless.yml should result in undefined.
Maybe we should update the documentation to make the default / fallback functionality more prominent.
medikoo
left a comment
There was a problem hiding this comment.
I think it's a good call, and best would be to we have a single source of truth.
In my opinion {self:provider.stage} should just work without surprises, and there should be no need for ${opt:stage, self:provider.stage} which looks as undesired complexity.
Implementation wise, I agree this should not be solved in lib/Serverless.js, but rather here:
serverless/lib/classes/Service.js
Line 22 in e5300a6
What did you implement:
Closes #4929
When the serverless.yml has no stage key, and you use the --stage flag, the LogGroup and function name will be named using the default dev stage.
For example we have serverless file like this
If look you can see that provider does not have stage but function name has reference on
${self:provider.stage}.When user deploys it and pass
--stageflag in cli it works a little bit strange.Cloudformation stack will be named OK but cloudwatch group name and function name will ignore it and will use always default stage('dev')
How did you implement it:
If
--stageflag was passed in cli it rewrites default stage 'dev', but it does not rewrite stage which was specified in provider section.How can we verify it:
Todos:
Is this ready for review?: YES
Is it a breaking change?: NO