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

AWS API Gateway provider.apiGateway.stage not working #11675

Closed
4 tasks done
mpage-hearsay opened this issue Jan 12, 2023 · 11 comments · Fixed by #11772
Closed
4 tasks done

AWS API Gateway provider.apiGateway.stage not working #11675

mpage-hearsay opened this issue Jan 12, 2023 · 11 comments · Fixed by #11772

Comments

@mpage-hearsay
Copy link

mpage-hearsay commented Jan 12, 2023

Are you certain it's a bug?

  • Yes, it looks like a bug

Is the issue caused by a plugin?

  • It is not a plugin issue

Are you using the latest v3 release?

  • Yes, I'm using the latest v3 release

Is there an existing issue for this?

  • I have searched existing issues, it hasn't been reported yet

Issue description

I am trying to override the AWS API Gateway Stage name as described here.

However, when I deploy it doesn't create a stage with the overridden name value. It still defaults to using the Serverless stage name for the new API Gateway Stage.

These are the URLs I see in the deployed API Gateway Stage(s):

https://asdfjkl.execute-api.my-region.amazonaws.com/dev/dev/f1
https://asdfjkl.execute-api.my-region.amazonaws.com/dev/dev/f2
https://asdfjkl.execute-api.my-region.amazonaws.com/prod/prod/f1
https://asdfjkl.execute-api.my-region.amazonaws.com/prod/prod/f2

Instead I want to have:

https://asdfjkl.execute-api.my-region.amazonaws.com/foobar/dev/f1
https://asdfjkl.execute-api.my-region.amazonaws.com/foobar/dev/f2
https://asdfjkl.execute-api.my-region.amazonaws.com/foobar/prod/f1
https://asdfjkl.execute-api.my-region.amazonaws.com/foobar/prod/f2

Service configuration (serverless.yml) content

provider:
  apiGateway:
    restApiId: 1111
    restApiRootResourceId: 2222
    stage: foobar
...

functions:
  func1:
    name: func1-${opt:stage, 'dev'}
    handler: bin/func1
    events:
      - http:
        path: /${opt:stage, 'dev'}/f1
        method: get
  func2:
    name: func2-${opt:stage, 'dev'}
    handler: bin/func2
    events:
      - http:
        path: /${opt:stage, 'dev'}/f2
        method: post

Command name and used flags

sls deploy --stage dev

Command output

N/A (deploys successfully).

Environment information

Running "serverless" from node_modules
Framework Core: 3.25.1 (local) 3.26.0 (global)
Plugin: 6.2.2
SDK: 4.3.2
@mpage-hearsay
Copy link
Author

FYI, I started a discussion for this but it's not getting any traction so I opened this issue.

@medikoo
Copy link
Contributor

medikoo commented Jan 12, 2023

@mpage-hearsay thanks for reporting. Indeed it looks there's a bug, as provider.apiGateway.stage is recognized as valid property, yet it seems ineffective.

PR with a fix is welcome!

@jattkaim
Copy link

I would love to know if this was ever working? Seems like the code change made in October was quite simple. I am also facing this issue & trying to debug how/where it is going wrong

@medikoo
Copy link
Contributor

medikoo commented Jan 13, 2023

I would love to know if this was ever working? Seems like the code change made in October was quite simple. I am also facing this issue & trying to debug how/where it is going wrong

As I checked, it didn't, see my comment in original PR

@jattkaim
Copy link

oh sorry! are we able to mention that PR here. This would be quite a crucial feature for a new SaaS application I was building based off the assumption that this was functional 😞 Happy to help but I currently do not know where to start haha 😢

@medikoo
Copy link
Contributor

medikoo commented Jan 13, 2023

#11487 (comment)

@mpage-hearsay
Copy link
Author

mpage-hearsay commented Jan 20, 2023

@medikoo a question I have about the fix.

What if the API Gateway stage already exists? Will the SLS deploy overwrite an existing stage with the given name?

I ask because we have stages/resources/methods that are defined/managed outside of serverless. In certain cases I want my serverless app to just add resources/methods to the existing gateway stage.

@medikoo
Copy link
Contributor

medikoo commented Jan 23, 2023

@medikoo a question I have about the fix. What if the API Gateway stage already exists?

Such a scenario should only be taken into account if service references an external API Gateway, then I believe updates done via AWS SDK are not considered at all (as we do not allow updating API-wide properties when we work with externally defined API) and when endpoints setup in CF are considered it is safe to define stage deployment (it won't break other endpoints deployments made to the same stage from eventual another stack)

@gmetzker
Copy link

Would be nice to see this work for ApiGatewayV2 as well. Something like:

provider:
  apiGateway:
    stage: customStageName

As a work around it seems to work if you add some partial content to the Resources section:

Resources:
  HttpApiStage:
    Type: AWS::ApiGatewayV2::Stage
    Properties:
      "StageName": "customStageName"

@kevb10
Copy link

kevb10 commented Feb 22, 2023

Would be nice to see this work for ApiGatewayV2 as well. Something like:

provider:
  apiGateway:
    stage: customStageName

As a work around it seems to work if you add some partial content to the Resources section:

Resources:
  HttpApiStage:
    Type: AWS::ApiGatewayV2::Stage
    Properties:
      "StageName": "customStageName"

the workaround here is confirmed to work. just make sure it's under resources like so

resources:
  Resources:
    HttpApiStage:
      Type: AWS::ApiGatewayV2::Stage
      Properties:
        "StageName": "customStageName"

suityou01 pushed a commit to suityou01/serverless that referenced this issue Mar 3, 2023
@theRocket
Copy link
Contributor

We have been using the following syntax and it's been working fine. Stage is at provider level.

  apiGateway:
    shouldStartNameWithService: true
    description: ${self:custom.description.${opt:stage}, self:custom.description.nonprod}
    usagePlan: ${file(./serverless/usage-plans.yml):usagePlan}
  stage: ${opt:stage}

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

Successfully merging a pull request may close this issue.

6 participants