跳至內容

如何解決使用自訂網域名稱調用 API Gateway REST 或 HTTP API 時的 403「Missing Authentication token」(缺少身分驗證權杖) 錯誤?

1 分的閱讀內容
0

我按照指示為我的 Amazon API Gateway REST 或 HTTP API 設定自訂網域。當我調用 API 時,我收到 403「Missing Authentication token」(缺少身分驗證權杖) 錯誤。

簡短說明

如果網址路徑不正確,則在調用 API 時,具有自訂網域名稱的 API Gateway API 會傳回 403「Missing Authentication token」(缺少身分驗證權杖) 錯誤。

**注意:**使用 API Gateway API 階段網址不會傳回 403「Missing Authentication token」(缺少身分驗證權杖) 錯誤。

解決方法

為 API Gateway API 設定的自訂網域名稱會使用 API 對應來連線至 API 階段,透過自訂網域名稱將流量傳送至 API。API 對應具有 API、階段、自訂網域名稱,以及可用於對應的選用路徑。如需詳細資訊,請參閱使用 API 對應

在下列範例中,自訂網域 "https://api.example.com" API 對應的設定如下:

API範例階段路徑預設網址自訂網域網址
abcd3456efAPI 1dev(none)https://abcd3456ef.execute-api.us-east-1.amazonaws.com/devhttps://api.example.com
wxyz1234abAPI 2測試訂單https://wxyz1234ab.execute-api.us-east-1.amazonaws.com/testhttps://api.example.com/orders
mnop5678qrAPI 3prod客戶https://mnop5678qr.execute-api.us-east-1.amazonaws.com/prodhttps://api.example.com/customers

在此範例組態中,使用 https://abcd3456ef.execute-api.us-east-1.amazonaws.com/dev/resourceA 網址向 API 1 發出的請求,會將流量順利路由到 "resourceA"。這是因為對階段名稱 "dev" 的資源提出請求。但是,使用 https://api.example.com/dev/resourceA 網址的相同請求會傳回 403「Missing Authentication token」(缺少身分驗證權杖) 錯誤。因為階段 "dev" 已對應至自訂網域名稱的 (none) 路徑,所以會發生此錯誤。若要使用自訂網域名稱將請求路由至 "resourceA",請確定網址為 https://api.example.com/resourceA。

同樣地,相當於 https://wxyz1234ab.execute-api.us-east-1.amazonaws.com/test/resourceB 的自訂網域名稱網址為 https://api.example.com/orders/resourceB。這是因為 API 2 的「測試」階段被對應到自訂網域 API 對應中的路徑「訂單」。

相關資訊

如何疑難排解 API Gateway 的 HTTP 403 錯誤?

如何對 API Gateway REST API 端點的 403「Missing Authentication token」(缺少身分驗證權杖) 錯誤進行疑難排解?

在 API Gateway 中設定區域自訂網域名稱