1
votes

I have an aws api gateway api that was using a api key to authenticate requests. It was tied to a usage plan and it was working. Later we needed a new api key name and value. I removed the old api key from usage plan and added the new api key to usage plan. Re-deployed the stage. Now when using the new api key name and value in the header the requests always return as 403 forbidden. Not sure what is wrong. Everything looks right.

1
Has the API key been attached to the same usage plan as the previous key? - Chris Williams
The first attempt I deleted the first key and reused the same key with different name. This did not work. I then made a whole new key name and value. That still does not work. - Andy N
Have you an example of the request you're making? Perhaps as a cURL request? Also to confirm the key is in the same account as the API Gateway resources - Chris Williams
Is a get url: xxxxxx.execute-api.us-west-2.amazonaws.com/get-something in the header: xxxx-api-key: xxxxxx - Andy N
The header you use must be x-api-key. The name of the key in API Gateway does not matter (an API can have many keys associated with it). - Chris Williams

1 Answers

1
votes

The header for an API key must be x-api-key, without this the API will return a 403 when API key authentication is enabled for the stage.

You distribute API keys to your customers and require them to pass the API key as the X-API-Key header of each incoming request.

The name of the key does not need to share this, in fact you can use it to describe the application/user who will be using this API key with your integration.

To call your API you would use the below where $key is the API key value.

curl -H "x-api-key: $key" https://xxxxxx.execute-api.us-west-2.amazonaws.com/get-token

You can find out more information about this in the Choose an API key source documentation.