Skip to content
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

shouldStartNameWithService ignored for HTTP API gateway #9631

Open
IlyaSemenov opened this issue Jun 21, 2021 · 8 comments · May be fixed by #9758
Open

shouldStartNameWithService ignored for HTTP API gateway #9631

IlyaSemenov opened this issue Jun 21, 2021 · 8 comments · May be fixed by #9758

Comments

@IlyaSemenov
Copy link

@IlyaSemenov IlyaSemenov commented Jun 21, 2021

For HTTP API gateways, provider.apiGateway.shouldStartNameWithService is ignored. The API gateway is always named as stage-service.

Expected

With shouldStartNameWithService enabled, HTTP API gateway is named as service-stage.

serverless.yml
service: xyz-web

provider:
  name: aws
  runtime: nodejs14.x
  lambdaHashingVersion: "20201221"
  endpointType: REGIONAL
  apiGateway:
    binaryMediaTypes:
      - "*/*"
    shouldStartNameWithService: true

package:
  patterns:
    - "!**"
    - dist/aws-lambda-handler/**
    - public/**

functions:
  vite:
    handler: dist/aws-lambda-handler/index.handler
    events:
      - httpApi: "*"
serverless deploy output
❯ yarn serverless deploy
yarn run v1.22.10
$ /Users/semenov/work/xyz-web/node_modules/.bin/serverless deploy
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
........
Serverless: Stack create finished...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service xyz-web.zip file to S3 (772.13 KB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
..............................
Serverless: Stack update finished...
Service Information
service: xyz-web
stage: dev
region: us-east-1
stack: xyz-web-dev
resources: 11
api keys:
  None
endpoints:
  ANY - https://yokkida.execute-api.us-east-1.amazonaws.com
functions:
  vite: xyz-web-dev-vite
layers:
  None

Installed version

❯ yarn serverless --version
yarn run v1.22.10
$ /Users/semenov/work/xyz-web/node_modules/.bin/serverless --version
Framework Core: 2.47.0 (local)
Plugin: 5.4.0
SDK: 4.2.3
Components: 3.12.0

The source of problem is clearly seen, for REST API this flag is taken into account:

// API Gateway
getApiGatewayName() {
if (this.provider.serverless.service.provider.apiName) {
return `${this.provider.serverless.service.provider.apiName}`;
}
return _.get(this.provider.serverless.service.provider.apiGateway, 'shouldStartNameWithService')
? `${this.provider.serverless.service.service}-${this.provider.getStage()}`
: `${this.provider.getStage()}-${this.provider.serverless.service.service}`;
},

and for HTTP API it is not:

// HTTP API
getHttpApiName() {
if (
this.provider.serverless.service.provider.httpApi &&
this.provider.serverless.service.provider.httpApi.name
) {
return `${String(this.provider.serverless.service.provider.httpApi.name)}`;
}
return `${this.provider.getStage()}-${this.provider.serverless.service.service}`;
},

@pgrzesik
Copy link
Member

@pgrzesik pgrzesik commented Jun 21, 2021

Hello 👋 Thanks for reporting. This is expected behavior, provider.apiGateway settings are only applicable to REST API (http event in configuration), where provider.httpApi settings are applicable to HTTP API (httpApi event in configuration).

Does that clarify the problem?

@IlyaSemenov
Copy link
Author

@IlyaSemenov IlyaSemenov commented Jun 21, 2021

It does clarify the problem, but the current behaviour where the naming is different between HTTP and REST gateways is far from perfect...don't you think? The global default is to put -stage as a suffix but with HTTP gateway this is not the case.

@pgrzesik
Copy link
Member

@pgrzesik pgrzesik commented Jun 22, 2021

Hello @IlyaSemenov - to be honest I wasn't aware that we have this same inconsistency for HTTP API - I was under impression that it was "mixed up" for REST API only. Given that, the setting that we have for REST API has became a bit problematic, as at first we wanted to migrate to that convention fully, but that would require redeployments of existing API Gateways which might be not desirable for a lot of people running in production. @medikoo, what do you think about exposting similar property for httpApi to allow changing the naming convention?

@medikoo
Copy link
Member

@medikoo medikoo commented Jun 22, 2021

@pgrzesik I'm taken by surprise as well (especially that I've implemented httpApi event). I assume I wanted to keep it consistent with http and that wasn't great decision.

Anyway in light of that, we're totally open to add support for provider.httpApi.shouldStartNameWithService. PR's welcome!

@thiagomr
Copy link

@thiagomr thiagomr commented Jun 23, 2021

Hey there. Could I get this one as my first issue here?

@medikoo
Copy link
Member

@medikoo medikoo commented Jun 24, 2021

@thiagomr definitely. We look forward the PR!

@thiagomr
Copy link

@thiagomr thiagomr commented Jun 25, 2021

@medikoo thanks, I'll send it soon!

@thiagomr
Copy link

@thiagomr thiagomr commented Jul 17, 2021

@medikoo Sorry by the delay on this. I'm sending the PR #9758. Let me know your thoughts about it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants