Skip to content

API Gateway Naming Convention #2918

Open

Description

@surfacedstudio

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.shouldStartNameWithService option (it still should be supported by schema, but using it should show deprecation)
  • Hardcode ${service}-${stage} API name, and remove any provider.apiGateway.shouldStartNameWithService option handling

Activity

  1. TCMiranda commented on Dec 30, 2016

    @TCMiranda

    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
    screenshot from 2016-12-30 10-31-27_censored

    Production API
    screenshot from 2016-12-30 10-31-44_censored

    Seems that with little effort my two services could be joined in one with two stages.. but I may be wrong 😊

    Thanks!

  2. markstos commented on Jan 24, 2017

    @markstos

    I recommend closing this issue as a dupe of #2445, which already focused on how stages are used in API Gateway.

  3. pmuens commented on Jan 25, 2017

    @pmuens
    Contributor

    Thanks for pointing in to the issue @markstos 👍 .

    I'll close this one as we can continue the discussion in #2445.

  4. medikoo commented on Aug 19, 2020

    @medikoo
    Contributor

    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)

  5. added
    bug/design
    and removed on Aug 19, 2020
  6. added
    deprecation
    on Oct 5, 2020
  7. medikoo commented on Oct 5, 2020

    @medikoo
    Contributor

    I've updated main description with implementation proposal

  8. removed
    deprecation
    on Oct 19, 2020
  9. sc0ttdav3y commented on Apr 28, 2021

    @sc0ttdav3y

    For those coming to this ticket in 2021 looking for answers, it looks like V3 of serverless will 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

  10. medikoo commented on Apr 28, 2021

    @medikoo
    Contributor

    We've actually decided to revert from that deprecation (reasoning: #9160 (comment)) still setting will remain working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    breakingbug/designcat/aws-event-api-gateway

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions