API Gateway - Execution failed: Resource forbidden due to invalid API Key

0

API gateway is returning:

< HTTP/2 403 
< date: Sun, 07 Jul 2024 02:51:24 GMT
< content-type: application/json
< content-length: 24
< x-amzn-requestid:
< x-amzn-errortype: BadRequestException
< x-amz-apigw-id:=
< 
* Connection #0 to host example.execute-api.ap-southeast-2.amazonaws.com left intact
{"message": "Forbidden"}%

when api key required is configured for a method.

In CloudWatch logs a single entry that says "Execution failed: Resource forbidden due to invalid API Key"

Things that have been checked in the web console:

  • key added to a usage plan
  • usage plan assigned to stage
  • api key is correct
  • request is being sent with "X-Api-Key"
  • key is correct
  • stage is deployed
  • method is correct
  • no other authroizer enabled
asked 14 days ago206 views
1 Answer
1
Accepted Answer

The API Gateway console doesn't seem to correctly handle the REST apis. If you perform the following the CLI

aws apigateway get-api-keys shows

you'll see that the keys are missing configuration for stageKeys

"stageKeys": []

You can set this using the CLI

aws apigateway update-api-key --api-key {KEY_ID} --patch-operations op='add',path='/stages',value='{API_GATEWAY_ID}/{STAGE}'

The change will take up to 5 minutes to apply (usually shorter)

answered 14 days ago
profile picture
EXPERT
reviewed 14 days ago
profile pictureAWS
EXPERT
reviewed 14 days ago