DianaIonita / serverless-api-gateway-throttling

A plugin for the Serverless framework which configures throttling for API Gateway endpoints.
ISC License
69 stars 7 forks source link

Cannot change path of httpApi event on lambda #33

Open HancoVisagie opened 1 year ago

HancoVisagie commented 1 year ago

Take this for example

  World:
    name: ${self:service}-${self:provider.stage}-WorldFunction
    handler: ${self:custom.handler.prefix}.UserHandler::World
    events:
      - httpApi:
          method: GET
          path: /world

deploy this, works fine, then do this:

  World:
    name: ${self:service}-${self:provider.stage}-WorldFunction
    handler: ${self:custom.handler.prefix}.UserHandler::World
    events:
      - httpApi:
          method: GET
          path: /world2

and I get the following error: Unable to find Route by key GET /world within the provided RouteSettings

Disable the extension and deployment succeeds.

DianaIonita commented 1 year ago

Hi @HancoVisagie,

Thank you for reporting the issue.

I think this is happening because endpoints and route throttling settings are distinct entities in API Gateway. It means that, when an endpoint path is removed or renamed, the route settings remain behind.

After you renamed your httpApi path, the throttling route defined for your old /world path stayed. When the plugin called API Gateway's updateStage to add the new /world2 route with its throttling settings, it failed because API Gateway expected it to include /world throttling settings.

Currently, you can fix the issue by manually removing your /world route settings. The plugin will then be able to create throttling settings for the new /world2 route:

image

As for a long term solution, I'm not sure yet. One way, I suppose, would be to make this plugin clean up routes before it tries defining throttling settings. I don't support this solution, because it wouldn't really know what it was cleaning up.

What are your thoughts?