-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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 service to be specified as object in serverless.yml #3521
Conversation
I did not want to trigger another endless naming discussion 😈 . So I just named the service object property |
Ok, this is making me really happy 💃 I have a question, we're planning to migrate an sls v0.x stack to v1.x. BUT before we can do this we should be able to append an Looking at the PR would the following be true? service:
name: foo-r getStackName();
// "foo-r" |
Ahh damn that would not be enough, the final stack name would become |
@nicka yes, that's currently the plan.
Hmm. That's bad. Maybe some plugin magic comes in handy here? |
Once this is merged could we do? service:
name: foo
stackName: ${self:service.name}-${opt:stage}-r
# OR
provider:
stackName: ${self:service.name}-${opt:stage}-r createStack() {
const stackName = this.provider.naming.getStackName(); // Update this logic |
Already tried this, but it's super embedded throughout the system. We're currently running a forked version which does the following, ideally this get's refactored and uses a general way to overwrite stack names. // Stack
getStackName() {
const name = `${this.provider.serverless.service.service}-${this.provider.getStage()}`;
if (this.provider.serverless.service.provider.preV1Resources) {
return `${name}-r`;
}
return name;
}, |
@nicka Agree that setting a custom stack name is a very valuable feature. But I think it is out of scope for this PR as it handles the possibility to specify the service as object. I suggest opening an additional feature request "Allow setting a custom stackname" that can be implemented after this has been merged. It could specify that /cc @eahefnawy @pmuens |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Just reviewed it @HyperBrain
Exactly what we need. Also big +1 for taking care of backwards compatibility 🥇
GTM
What did you implement:
Closes #3513
How did you implement it:
If the parser encounters an object typed service property it sets
service.service
to the service name (retrieved fromservice.name
). This is done for compatibility reasons because lots of plugins (core and 3rd party) useservice.service
directly to get the service name.The object is stored into the service as
service.serviceObject
and all of its properties can be accessed withservice.serviceObject.XXXXX
.In case the service property is a string,
service.service
is set to this andservice.serviceObject
is{ name: XXXX }
.Additionally I added a
service.getServiceName()
method to provide an option for plugins to become more robust against changes in the serverless object structure andservice.getServiceObject()
that returns the object or objectified service definition.How can we verify it:
Declare your service as object in the serverless.yml:
Compatibility checks can be made with any existing serverless.yml that sets the property as string.
Todos:
Is this ready for review?: YES
Is it a breaking change?: NO