Using existing Api Key and associate it with Api Gateway

Hello there!

I am trying to deploy a stack, that would have an API Gateway with API Key required for usage. However, I want to use pre-defined, manually created API Keys for some (or all) stages, as I don’t want them to be removed by accident (rotating API keys would be very painful), and also I don’t want key values to be exposed to developers. In other words, I don’t want the developers to have control over lifecycle of API Keys, but I want them (the keys) to be used within my Serverless stack to automatically protect functions.

The issue is that when using api key configuration within provider, deployment always creates a new key, even if a key with the same name already exists.

provider:
  # some other config here
  apiKeys:
    - name: test-key-iss
  apiKeySourceType: HEADER

I’ve seen a similar issue on the forum, but it was resolved with involving usage plans. My problem here is that I can’t just enable that at the moment, as there are other teams using the same AWS Account, that might not want to enable that yet. So, I would like to stick to just assigning already existing Api Key to an Api Gateway deployed with Serverless, and that my http endpoints for functions are using it.

Is that currently possible to achieve?

1 Like

I have the same issue. Creating resources directly using cloudformation template under resources throws error. It would be great to have that feature in sls template to be able to use the existing API.

An error occurred: ServiceUsagePlan - API Stage not found: xxxx:dev (Service: AmazonApiGateway; Status Code: 404; Error Code: NotFoundException;