Failed to associate api key with usage plan (Invalid API Identifier)

Hi Serverless community,

I’m trying to add an API key to an api gateway activated lambda function, but I run into an error related to using an “Invalid API Identifier”. More below.

I’ve followed this documentation exactly, but my serverless deploy fails with the following error when I attempt to deploy:

AddApiKey: Creating new api key UnrestrictedUsageKey
AddApiKey: Created new api key UnrestrictedUsageKey:9mp219azw3
AddApiKey: Creating new usage plan UnrestrictedUsageKey-usage-plan
AddApiKey: Associating api key 9mp219azw3 with usage plan 1o93l4
AddApiKey: Failed to associate api key with usage plan. Error Invalid API identifier specified 425359244402:null
AddApiKey: Failed to add api key the service. Error Invalid API identifier specified 425359244402:null
AddApiKey: UnrestrictedUsageKey - hKSp8MQW6t5WXLGyAXUXD3oIyouVsBeJrUrbSsq7

I’m not sure where this API identifier is coming from. I’ve tried running serverless remove and re-executing to start from scratch, but I get the same error (with the same API identifier). It successfully deploys the new API and the function works as expected, but it still succeeds when I call it without an API key.

This is the relevant snippet from my serverless.yaml:

plugins:
  - serverless-add-api-key

custom:
  apiKeys:
    - name: UnrestrictedUsageKey

Any ideas to solve would be very much appreciated!

Checked the code which needs ServiceEndpoint as output in the yml
example

  Outputs:
    ServiceEndpoint:
      Description: API endpoint
      Value:
        Fn::Join:
        - ''
        - - 'https://'
          - Ref: ApiGatewayRestApi
          - '.execute-api.'
          - ${self:provider.region}
          - '.amazonaws.com/'
          - ${self:provider.stage}

Hi, did you found the solution on this issue?