本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
在 APIs中測試 REST API 的使用計劃
以在 教學課程:匯入範例來建立 REST API 中建立的 PetStore API 為例。假設 API 設定使用 Hiorr45VR...c4GJc
的 API 金鑰。下列步驟說明如何測試用量計劃。
測試您的用量計劃
-
在用量計劃中,對 API (例如
GET
) 的 Pets 資源 (/pets
) 提出?type=...&page=...
請求,查詢參數為xbvxlpijch
: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}
注意
您必須向 API Gateway 的
execute-api
元件提交此請求,並在所需的Hiorr45VR...c4GJc
標頭中提供需要的 API 金鑰 (例如x-api-key
)。成功的回應會傳回
200 OK
狀態碼和包含後端請求結果的承載。如果您忘記設定x-api-key
標頭或以錯誤的金鑰設定它,您會收到403 Forbidden
回應。不過,如果您並未設定方法要求 API 金鑰,您可能會收得200 OK
回應,無論您是否正確設定x-api-key
標頭,而且會略過用量計劃的調節和配額限制。有時,當發生 API Gateway 無法強制用量計劃調節限制或請求配額的內部錯誤時,API Gateway 會提供請求,但不會套用用量計劃指定的調節限制或配額。但是,它會在您的 CloudWatch 中記錄
Usage Plan check failed due to an internal error
錯誤訊息。您可以忽略這類偶發的錯誤。