Calling api gateway returns 403 and error about api key within CI but is fine outside of CI (Codebuild)

1k Views Asked by At

Using Cloudformation I have created an API Gateway and Usage Plan and then use the CLI/SDK to create an API Key. All this happens within our CI process. Then we test that the api returns the correct results (using dredd), however it fails with the following error:

API Key **********************************Rp9Mjh not authorized because method 'GET /bookings' requires API Key and API Key is not associated with a Usage Plan for API Stage XXXX/Prod: No Usage Plan found for key and API Stage

When I test the key outside of Codebuild (ie postman) it works fine. Could somebody offer a suggestion of what could be wrong as I'm not sure why the exact same request fails from within Codebuild but runs fine outside.

1

There are 1 best solutions below

1
On

Adding a sleep in the buildspec has fixed this. Apparently when api gateway generates the key its not available straight away.