Repository navigation
Description
Most resources created by serverless (roles, lambdas) are named resourceName-[stage]. However, API Gateway naming does not follow this convention and instead uses [stage]-resourceName. Is there a reason for this?
From naming.js:
getApiGatewayName() {
return `${this.provider.getStage()}-${this.provider.serverless.service.service}`;
}
Using the stage as a suffix rather than a prefix allows the different API gateways to remain grouped within the AWS console and allows for cleaner IAM permissions to be applied across stages.
Is there a way to change this? Otherwise I'm happy to add at least the option to set a custom name like
provider:
apiGatewayName: my-gateway-name-${opt:stage}
Happy to create a PR or being told that I'm totally missing the way in which I can already do that ;)
Implementation proposal
All breaking features needs to be first announced as deprecations, therefore we need to implement it as follows:
1. Against master branch
Addressed with #8339
Details
- Introduce `provider.apiGateway.shouldStartNameWithService` boolean option (_false_ by default), and support just `true` value - If option is missing show [deprecation message](https://github.com/serverless/serverless/blob/master/CONTRIBUTING.md#configuring-deprecations) - if option is set (obviously to `true`, generate API name as `${service}-${stage}`2. Against v{new major}-pre branch
To be implemented when given branch is created
- Remove introduced deprecation
- Deprecate
provider.apiGateway.shouldStartNameWithServiceoption (it still should be supported by schema, but using it should show deprecation) - Hardcode
${service}-${stage}API name, and remove anyprovider.apiGateway.shouldStartNameWithServiceoption handling
Activity
TCMiranda commentedon Dec 30, 2016
Beyond the naming convention, it seems wrong to append
-[stage]to the ApiGateway api name. In practice, it ignores the standard ApiGateway stages configuration.What is weird is that the api stage follows the stage defined on the service.
Example:
Development API

Production API

Seems that with little effort my two services could be joined in one with two stages.. but I may be wrong 😊
Thanks!
markstos commentedon Jan 24, 2017
I recommend closing this issue as a dupe of #2445, which already focused on how stages are used in API Gateway.
pmuens commentedon Jan 25, 2017
Thanks for pointing in to the issue @markstos 👍 .
I'll close this one as we can continue the discussion in #2445.
medikoo commentedon Aug 19, 2020
Reopening as it addresses different concern than #2445 (which is about using AWS stages for stages), while this issue questions service and stage order in API name (and that's valid concern imo)
medikoo commentedon Oct 5, 2020
I've updated main description with implementation proposal
sc0ttdav3y commentedon Apr 28, 2021
For those coming to this ticket in 2021 looking for answers, it looks like V3 of
serverlesswill implement API gateway naming as${service}-${stage}as many have asked for. You can adopt this now with a config setting.https://www.serverless.com/framework/docs/deprecations#api-gateway-naming-will-be-changed-to-service-stage
medikoo commentedon Apr 28, 2021
We've actually decided to revert from that deprecation (reasoning: #9160 (comment)) still setting will remain working