當我使用 Amazon API Gateway向 API 發送請求時,我會收到「429 請求太多」或「超過限制」錯誤。
簡短說明
如果您超過配額限流限制,則會收到「429 請求太多」或「超過限制」的錯誤回應。API Gateway 具有每個區域的帳戶層級配額。如需有關限流相關設定的詳細資訊,請參閱如何在 API Gateway 中套用限流限制設定。
解決方法
首先,請確認您是否已按照指示啟動 Amazon CloudWatch Logs 以進行 API Gateway 疑難排解。若要僅針對發生錯誤的 API 請求產生事件日誌,請確定您選擇 ERROR。然後,使用 CloudWatch 主控台檢視記錄的 API 請求和回應。
「429 請求太多」錯誤
檢查您針對使用方案的 API 階段設定的每個用戶端或每種方法限流限制的速率或高載限制。當超過速率或高載限制時,CloudWatch 事件會記錄超過限流限制。錯誤看起來類似下列訊息:
(f277a0b4-2bcd-41b3-8e43-4de770663ffb) API Key
**********************************
F0yrv6 exceeded throttle limit for API
Stage rohkz08x02/dev: Key throttle limit exceeded for Usage Plan ID nnpegc, RestApi rohkz08x02, Stage dev, Resource f646q2, HttpMethod GET. Limit: 5.00 Burst: 10
若要解決此錯誤,請使用具有抖動指數退避的標準重試模式,然後重新提交 API 請求。如需詳細資訊,請參閱重試行為。
「超過限制」錯誤
當您收到此錯誤時,限額限制超過您的 API Gateway使用方案限制。CloudWatch 執行會記錄超過配額限制。錯誤看起來類似下列訊息:
(7b819c41-e0a0-433a-883e-bc461fd70fd6) API Key
**********************************
F0yrv6 exceeded quota limit for API
Stage rohkz08x02/dev: Key quota exhausted for Usage Plan ID nnpegc. Q
Limit: 500 Period: DAY
若要解決此錯誤,請擴展配額。
相關資訊
如何對 Lambda 函數限流的「速率超出」和 429「TooManyRequestsException」錯誤進行疑難排解?
如何在我的 CloudWatch Logs 中尋找 API Gateway REST API 錯誤?