

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

# 如何變更安全政策
<a name="apigateway-security-policies-update"></a>

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

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

------
#### [ AWS 管理主控台 ]

**變更 API 的安全政策**

1. 在以下網址登入 API Gateway 主控台：[https://console.aws.amazon.com/apigateway](https://console.aws.amazon.com/apigateway)。

1. 選擇 REST API。

1. 選擇 **API 設定**，然後選擇**編輯**。

1. 針對**安全政策**，選取以 開頭的新政策`SecurityPolicy_`。

1. 針對**端點存取模式**，選擇**嚴格**。

1. 選擇**儲存變更**。

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

------
#### [ AWS CLI ]

下列 [update-rest-api](https://docs.aws.amazon.com/cli/latest/reference/apigateway/update-rest-api.html) 命令會更新 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](https://docs.aws.amazon.com/cli/latest/reference/apigateway/update-rest-api.html) 命令會更新使用增強型安全政策來使用`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"
}
```

------