如何更改安全策略 - Amazon API Gateway
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

如何更改安全策略

您可以更改 API 的安全策略。如果您通过自定义域名向 API 发送流量,API 和自定义域名无需具有相同的安全策略。当您调用该自定义域名时,API Gateway 会使用 API 的安全策略来协商 TLS 握手。但是,为了保持一致性,建议您对自定义域名和 API 使用相同的安全策略。

如果您更改安全策略,大约需要 15 分钟才能完成更新。您可以监控您的 API 的 apiStatus。当您的 API 更新时,apiStatusUPDATING,更新完成后,它将变为 AVAILABLE。当您的 API 正在更新时,您仍然可以调用它。

Amazon Web Services 管理控制台
更改 API 的安全策略
  1. 通过以下网址登录到 Amazon API Gateway 控制台:https://console.aws.amazon.com/apigateway

  2. 选择一个 REST API。

  3. 选择 API 设置,然后选择编辑

  4. 对于安全策略,选择一个以 SecurityPolicy_ 开头的新策略。

  5. 对于端点访问模式,请选择严格

  6. 选择保存更改

    重新部署 API 以使更改生效。由于您已将端点访问模式更改为严格,因此大约需要 15 分钟,更改才能完全传播。

Amazon 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 命令会将使用增强型安全策略的 API 更新为使用 TLS_1_0 安全策略。

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" }