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

Allow custom stage for HTTP API #334

Closed
webpepper opened this issue May 7, 2020 · 5 comments · Fixed by #546
Closed

Allow custom stage for HTTP API #334

webpepper opened this issue May 7, 2020 · 5 comments · Fixed by #546
Labels

Comments

@webpepper
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Bug Report

Error Description

When using HTTP API the stage seems to be hardcoded to $default.

const params = {
  ApiId: domain.apiId,
  ApiMappingKey: domain.basePath,
  DomainName: domain.givenDomainName,
  Stage: domain.apiType === Globals.apiTypes.http ? "$default" : domain.stage, // <-- bug??
};

See

Stage: domain.apiType === Globals.apiTypes.http ? "$default" : domain.stage,

Currently it's impossible to use anything other than the $default stage with this plugin.

Command Run
sls deploy

Console Output

Serverless: [AWS apigatewayv2 400 0.928s 0 retries] createApiMapping({
  ApiId: 'xxx',
  ApiMappingKey: 'dev',
  DomainName: 'xxx',
  Stage: '$default'
})
Serverless Domain Manager: Error: xxx:  BadRequestException: Invalid stage identifier specified
Serverless Domain Manager: Error: xxx:  Error: Error: xxx: Unable to create basepath mapping.

Domain Manager Configuration

custom:
  customDomain:
    domainName: somedomain.com
    basePath: dev
    stage: dev
    certificateName: somedomain.com
    createRoute53Record: true
    endpointType: 'regional'
    apiType: http
    securityPolicy: tls_1_2
    hostedZoneId: XYZ

Versions

  • Domain Manager version(s): 4.0.0
  • Node/npm version: 12.16.1/6.13.4
  • Serverless Version: 1.69.0
  • Lambda Code: Javascript

Possible Solution

Replace

Stage: domain.apiType === Globals.apiTypes.http ? "$default" : domain.stage

With

Stage: domain.apiType === Globals.apiTypes.http ? (domain.stage || "$default") : domain.stage
@webpepper webpepper added the bug label May 7, 2020
@tehnrd
Copy link
Contributor

tehnrd commented May 12, 2020

Hmm, so I recall working on this and it was based on the related conversation here: serverless/serverless#7052 (comment) and serverless/serverless#7331

...where the Serverless framework will always deploy HTTP APIs to the $default stage as the serverless framework doesn't really use stages and creates an entirely different API for each "stage".

What is the use case you have for a defined stage instead of $default?

You might be able to drop stage from the serverless domain config if it isn't necessary.

@tehnrd
Copy link
Contributor

tehnrd commented May 12, 2020

Looks like they reverted that change and added back support for paths, so it would make sense to fix this. serverless/serverless#7383

@webpepper
Copy link
Author

The original need for this was migration from the REST API. Even if I don't need multiple stages right now, API Gateway supports them. So not allowing to use them in this plugin is a limitation.

This reasoning doesn't work in my case:

creates an entirely different API for each "stage"

Mainly due CloudFormation's 200 resource limit I split API creation into its own separate stack.

Since this HTTP API is being created in the Resources section, theoretically I'm not limited by the number of stages I can create.

Then in other stacks with lambdas/endpoints I reuse this previously created HTTP API resource. So I should be able to use this API by referencing it (related to #335) and specifying a stage to which I want to deploy and link my domain.

@tiagoramalho
Copy link

Hello,
I have one doubt regarding the $default stage.
When I want to deploy an HTTP API, the $default stage is not automatically created, and I always get the error "BadRequestException: Invalid stage identifier specified".

When I manually create the $default stage in the API everything works fine. There is any way how I could automate that creation?

@hope-portal-services
Copy link

Any intention of implementing this? It's an odd limitation.

@rddimon rddimon linked a pull request Feb 6, 2023 that will close this issue
@rddimon rddimon mentioned this issue Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants