禁用 REST API 的默认端点 - Amazon API Gateway
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

禁用 REST API 的默认端点

默认情况下,客户端可以通过使用 API Gateway 为 API 生成的 execute-api 端点来调用您的 API。为确保客户端只能通过使用自定义域名访问您的 API,请禁用默认 execute-api 端点。客户端仍然可以连接到您的默认端点,但它们会收到 403 Forbidden 状态码。禁用默认端点会影响 API 的所有阶段。当您更新任何阶段上的任何设置(例如,更新阶段上的部署)时,此设置就会生效。

以下过程说明了如何禁用 REST API 的默认端点。

Amazon Web Services Management Console
  1. 通过以下网址登录到 Amazon API Gateway 控制台:https://console.aws.amazon.com/apigateway

  2. 选择一个 REST API。

  3. 在主导航窗格中,选择 API 设置

  4. 选择一个 API。

  5. API 详细信息选项卡上,选择编辑

  6. 对于默认端点,选择非活动

  7. 选择保存更改

  8. 在主导航窗格中,选择资源

  9. 选择部署 API

  10. 将 API 重新部署到阶段或更新阶段上的任何设置,以使更新生效。

Amazon CLI

使用以下 update-rest-api 命令禁用默认端点:

aws apigateway update-rest-api \ --rest-api-id abcdef123 \ --patch-operations op=replace,path=/disableExecuteApiEndpoint,value='True'

禁用默认端点后,必须部署 API 才能使更改生效。

以下 create-deployment 命令创建部署并将其与某个阶段关联:

aws apigateway create-deployment \ --rest-api-id abcdef123 \ --stage-name dev