

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

# 停用 REST API 的預設端點
<a name="rest-api-disable-default-endpoint"></a>

預設情況下，用戶端可以使用 API Gateway 為 API 產生的 `execute-api` 端點來調用 API。若要確保用戶端只能使用自訂網域名稱來存取您的 API，請停用預設 `execute-api` 端點。用戶端仍然可以連線到您的預設端點，但會收到 `403 Forbidden` 狀態碼。停用預設端點會影響 API 的所有階段。當您更新任何階段上的任何設定時 (例如，更新階段上的部署)，此設定就會生效。

以下程序顯示如何停用 REST API 的預設端點。

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

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

1. 選擇 REST API。

1. 在主要導覽窗格中，選擇 **API 設定**。

1. 選擇一個 API。

1. 在 **API 詳細資訊**上，選擇**編輯**。

1. 針對**預設端點**，選取**非作用中**。

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

1. 在主要導覽窗格中，選擇**資源**。

1. 選擇**部署 API**。

1. 將您的 API 重新部署至階段，或更新階段上的任何設定，以讓更新生效。

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

以下 [update-rest-api](https://docs.aws.amazon.com/cli/latest/reference/apigateway/update-rest-api.html) 命令會停用預設端點：

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

停用預設端點之後，您必須部署 API，變更才會生效。

以下 [create-deployment](https://docs.aws.amazon.com/cli/latest/reference/apigateway/create-deployment.html) 命令會建立部署，並將其與階段建立關聯：

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

------