如何變更安全政策 - Amazon API Gateway

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

如何變更安全政策

您可以變更 API 的安全政策。如果您要透過自訂網域名稱將流量傳送至 APIs,則 API 和自訂網域名稱不需要具有相同的安全政策。當您叫用該自訂網域名稱時,API Gateway 會使用 API 的安全政策來交涉 TLS 交握。不過,為了保持一致性,我們建議您針對自訂網域名稱和 API 使用相同的安全政策。

如果您變更安全政策,更新大約需要 15 分鐘才能完成。您可以監控 API apiStatus的 。隨著 API 更新, apiStatusUPDATING ,當它完成時,它將是 AVAILABLE。更新 API 時,您仍然可以叫用它。

AWS 管理主控台
變更 API 的安全政策
  1. 在以下網址登入 API Gateway 主控台:https://console.aws.amazon.com/apigateway

  2. 選擇 REST API。

  3. 選擇 API 設定,然後選擇編輯

  4. 針對安全政策,選取以 開頭的新政策SecurityPolicy_

  5. 針對端點存取模式,選擇嚴格

  6. 選擇儲存變更

    重新部署 API 以使變更生效。由於您將端點存取模式變更為嚴格,變更完全傳播大約需要 15 分鐘。

AWS CLI

下列 update-rest-api 命令會更新 API 以使用SecurityPolicy_TLS13_1_3_2025_09安全政策:

aws apigateway update-rest-api \ --rest-api-id abcd1234 \ --patch-operations '[ { "op": "replace", "path": "/securityPolicy", "value": "SecurityPolicy_TLS13_1_3_2025_09" }, { "op": "replace", "path": "/endpointAccessMode", "value": "STRICT" } ]'

輸出將如下所示:

{ "id": "abcd1234", "name": "MyAPI", "description": "My API with a new security policy", "createdDate": "2025-02-04T11:47:06-08:00", "apiKeySource": "HEADER", "endpointConfiguration": { "types": [ "REGIONAL" ], "ipAddressType": "dualstack" }, "tags": {}, "disableExecuteApiEndpoint": false, "securityPolicy": "SecurityPolicy_TLS13_1_3_2025_09", "endpointAccessMode": "STRICT" "rootResourceId": "efg456" }

下列 update-rest-api 命令會更新使用增強型安全政策來使用TLS_1_0安全政策的 API。

aws apigateway update-rest-api \ --rest-api-id abcd1234 \ --patch-operations '[ { "op": "replace", "path": "/securityPolicy", "value": "TLS_1_0" }, { "op": "replace", "path": "/endpointAccessMode", "value": "" } ]'

輸出將如下所示:

{ "id": "abcd1234", "name": "MyAPI", "description": "My API with a new security policy", "createdDate": "2025-02-04T11:47:06-08:00", "apiKeySource": "HEADER", "endpointConfiguration": { "types": [ "REGIONAL" ], "ipAddressType": "dualstack" }, "tags": {}, "disableExecuteApiEndpoint": false, "securityPolicy": "TLS_1_0", "rootResourceId": "efg456" }