Test usage plans for REST APIs in API Gateway
As an example, let's use the PetStore API, which was created in Tutorial: Create a REST API by importing an
example. Assume that the API is
configured to use an API key of Hiorr45VR...c4GJc. The following steps
describe how to test a usage plan.
To test your usage plan
-
Make a
GETrequest on the Pets resource (/pets), with the?type=...&page=...query parameters, of the API (for example,xbvxlpijch) in a usage plan:GET /testStage/pets?type=dog&page=1 HTTP/1.1 x-api-key: Hiorr45VR...c4GJc Content-Type: application/x-www-form-urlencoded Host: xbvxlpijch.execute-api.ap-southeast-1.amazonaws.com X-Amz-Date: 20160803T001845Z Authorization: AWS4-HMAC-SHA256 Credential={access_key_ID}/20160803/ap-southeast-1/execute-api/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-api-key, Signature={sigv4_hash}Note
You must submit this request to the
execute-apicomponent of API Gateway and provide the required API key (for example,Hiorr45VR...c4GJc) in the requiredx-api-keyheader.The successful response returns a
200 OKstatus code and a payload that contains the requested results from the backend. If you forget to set thex-api-keyheader or set it with an incorrect key, you get a403 Forbiddenresponse. However, if you didn't configure the method to require an API key, you will likely get a200 OKresponse whether you set thex-api-keyheader correctly or not, and the throttle and quota limits of the usage plan are bypassed.Occasionally, when an internal error occurs where API Gateway is unable to enforce usage plan throttling limits or quotas for the request, API Gateway serves the request without applying the throttling limits or quotas as specified in the usage plan. But, it logs an error message of
Usage Plan check failed due to an internal errorin CloudWatch. You can ignore such occasional errors.