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

Bug: REST API usage plan ignores 'apiGateway.stage' parameter #12349

Open
4 tasks done
barys-liutkouski opened this issue Feb 9, 2024 · 0 comments · May be fixed by #12350
Open
4 tasks done

Bug: REST API usage plan ignores 'apiGateway.stage' parameter #12349

barys-liutkouski opened this issue Feb 9, 2024 · 0 comments · May be fixed by #12350

Comments

@barys-liutkouski
Copy link

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

When deploying a REST API with a usage plan, the generated usage plan template attempts to reference the provider.stage parameter, instead of provider.apiGateway.stage (when configured).

This results in an error when deploying the stack.

Serverless.yml configuration:

provider:
  name: aws
  runtime: nodejs18.x
  apiGateway:
    stage: api-2 # this is the part that gets ignored
    usagePlan:
      throttle:
        burstLimit: 500
        rateLimit: 1000

Resulting UsagePlan resource:

"ApiGatewayUsagePlan": {
  "Type": "AWS::ApiGateway::UsagePlan",
  "DependsOn": "ApiGatewayDeployment1707470569325",
  "Properties": {
    "ApiStages": [
      {
        "ApiId": {
          "Ref": "ApiGatewayRestApi"
        },
        "Stage": "dev" // `dev` stage is referenced even though `api-2` is set as the apiGateway stage
      }
    ],
    "Description": "Usage plan for usage-plan-repro dev stage",
    "UsagePlanName": "usage-plan-repro-dev",
    "Throttle": {
      "BurstLimit": 500,
      "RateLimit": 1000
    }
  }
}

Root cause seems to be that usage-plan.js uses that.provider.getStage() to set the stage, instead of this.provider.getApiGatewayStage().

I will submit a PR with a fix.

Service configuration (serverless.yml) content

service: usage-plan-repro
frameworkVersion: '3'

provider:
  name: aws
  runtime: nodejs18.x
  apiGateway:
    stage: api-2
    metrics: true
    usagePlan:
      throttle:
        burstLimit: 500
        rateLimit: 1000
      

functions:
  api:
    handler: index.handler
    events:
      - http:
          path: /
          method: get

Command name and used flags

serverless deploy

Command output

> serverless deploy

Deploying usage-plan-repro to stage dev (us-east-1)

✖ Stack usage-plan-repro-dev failed to deploy (114s)
Environment: darwin, node 18.18.0, framework 3.38.0 (local), plugin 7.2.0, SDK 4.5.1
Credentials: Local, "personal" profile
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
CREATE_FAILED: ApiGatewayUsagePlan (AWS::ApiGateway::UsagePlan)
Resource handler returned message: "API Stage not found: aisl7hvubb:dev (Service: ApiGateway, Status Code: 404, Request ID: 20d73366-b153-41a5-8813-312fa693befd)" (RequestToken: 04927a79-fa5c-c410-0f88-1a14a7a1058c, HandlerErrorCode: NotFound)

Environment information

Framework Core: 3.38.0 (local)
Plugin: 7.2.0
SDK: 4.5.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant