

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

# 發布 HTTP API 以供客戶調用
<a name="http-api-publish"></a>

您可以使用階段和自訂網域名稱來發布 API，以供用戶端呼叫。

API 階段是 API 生命週期狀態的邏輯參考 (例如，`dev`、`prod`、`beta` 或 `v2`)。每個階段都是 API 部署的具名參考，且可供用戶端應用程式呼叫。您可以為 API 的每個階段設定不同的整合和設定。

您可以使用自訂網域名稱來提供更簡單、更直覺的 URL，讓用戶端呼叫您的 API，而非預設的 URL `https://api-id.execute-api.region.amazonaws.com/stage`。

**注意**  
為了增強 API Gateway API 的安全性，`execute-api.{region}.amazonaws.com` 網域會在[公用尾碼清單 (PSL](https://publicsuffix.org/)) 中註冊。為了加強安全性，如果您需要在 API Gateway API 的預設網域名稱中設定敏感性 Cookie，我們建議您使用具 `__Host-` 前置詞的 Cookie。此做法將有助於保護您的網域免受跨站請求偽造 (CSRF) 攻擊。如需更多資訊，請參閱 Mozilla 開發人員網路中的[設定 Cookie](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#cookie_prefixes) 頁面。

**Topics**
+ [API Gateway 中 HTTP API 的階段](http-api-stages.md)
+ [API Gateway 中 HTTP API 的安全政策](http-api-ciphers.md)
+ [API Gateway 中 HTTP API 的自訂網域名稱](http-api-custom-domain-names.md)

# API Gateway 中 HTTP API 的階段
<a name="http-api-stages"></a>

API 階段是 API 生命週期狀態的邏輯參考 (例如，`dev`、`prod`、`beta` 或 `v2`)。API 階段是由其 API ID 及階段名稱來識別，而且它們會包含在您用來呼叫 API 的 URL 中。每個階段都是 API 部署的具名參考，且可供用戶端應用程式呼叫。

您可以建立從 API URL 基礎提供的 `$default` 階段，例如 `https://{api_id}.execute-api.{region}.amazonaws.com/`。您可以使用此 URL 來呼叫 API 階段。

部署是 API 組態的快照。將 API 部署到階段之後，用戶端就可以叫用它。您必須部署 API 才能讓變更生效。如果您啟用自動部署，則會自動為您發行 API 的變更。

# 在 API Gateway 中使用 HTTP API 的階段變數
<a name="http-api-stages.stage-variables"></a>

階段變數是您可為 HTTP API 定義階段的索引鍵/值對。它們的作用如同環境變數，而且可用於 API 設定。

階段變數並非用於敏感資料，例如登入資料。若要將敏感資料傳遞至整合，請使用 AWS Lambda 授權方。您可以將敏感資料傳遞至 Lambda 授權方輸出中的整合。如需進一步了解，請參閱[Lambda 授權方回應格式](http-api-lambda-authorizer.md#http-api-lambda-authorizer.payload-format-response)。

## 範例 – 使用階段變數自訂 HTTP 整合端點
<a name="http-api-stages.stage-variables-examples"></a>

例如，您可以定義階段變數，然後將其值設定為 HTTP Proxy 整合的 HTTP 端點。稍後，您可以使用相關聯的階段變數名稱來參照端點。如此，您可以在每個階段使用不同的端點來使用相同的 API 設定。同樣地，您可以使用階段變數，為 API 的每個階段指定不同的 AWS Lambda 函數整合。

若要使用階段變數來自訂 HTTP 整合端點，您必須先將階段變數 (例如，`url`) 的名稱和值設定為 `example.com`。之後，設定 HTTP 代理整合。您可以告訴 API Gateway 使用階段變數值 **http://\$1\$1stageVariables.url\$1**，而不需要輸入端點的 URL。此值會指示 API Gateway 在執行時間替換您的階段變數 `${}`，視您 API 的階段而定。

您可以使用類似的方式來參考階段變數，以指定 Lambda 函數名稱或 AWS 角色 ARN。

將 Lambda 函數名稱指定為階段變數值時，您必須在 Lambda 函數中手動設定許可。以下 [add-permission](https://docs.aws.amazon.com/cli/latest/reference/lambda/add-permission.html) 命令會設定 Lambda 函式的許可：

```
aws lambda add-permission --function-name arn:aws:lambda:XXXXXX:your-lambda-function-name --source-arn arn:aws:execute-api:us-east-1:YOUR_ACCOUNT_ID:api_id/*/HTTP_METHOD/resource --principal apigateway.amazonaws.com --statement-id apigateway-access --action lambda:InvokeFunction
```

# API Gateway 中適用於 HTTP API 的 API Gateway 階段變數參考
<a name="http-api-stages.stage-variables-reference"></a>

在下列情況下，您可以針對 HTTP API 使用 API Gateway 階段變數。

## HTTP 整合 URI
<a name="http-api-stages.stage-variables-in-integration-HTTP-uris"></a>

您可以使用階段變數作為 HTTP 整合 URI 的一部分，如下例範例所示。
+ 不含通訊協定的完整 URI – `http://${stageVariables.<variable_name>}`
+ 完整的網域 – `http://${stageVariables.<variable_name>}/resource/operation`
+ 子網域 – `http://${stageVariables.<variable_name>}.example.com/resource/operation`
+ 路徑 – `http://example.com/${stageVariables.<variable_name>}/bar`
+ 查詢字串 – `http://example.com/foo?q=${stageVariables.<variable_name>}` 

## Lambda 函式
<a name="http-api-stages.stage-variables-in-integration-lambda-functions"></a>

 您可以使用階段變數取代 Lambda 函數整合名稱或別名，如下列範例所示。
+ `arn:aws:apigateway:<region>:lambda:path/2015-03-31/functions/arn:aws:lambda:<region>:<account_id>:function:${stageVariables.<function_variable_name>}/invocations`
+ `arn:aws:apigateway:<region>:lambda:path/2015-03-31/functions/arn:aws:lambda:<region>:<account_id>:function:<function_name>:${stageVariables.<version_variable_name>}/invocations`

**注意**  
若要使用 Lambda 函數的階段變數，函數必須與 API 位於相同的帳戶中。階段變數不支援跨帳戶 Lambda 函數。

## AWS 整合憑證
<a name="http-api-stages.stage-variables-in-integration-aws-credentials"></a>

 您可以使用階段變數做為 AWS 使用者或角色登入資料 ARN 的一部分，如下列範例所示。
+  `arn:aws:iam::<account_id>:${stageVariables.<variable_name>}` 

# API Gateway 中 HTTP API 的安全政策
<a name="http-api-ciphers"></a>

API Gateway 會針對所有 HTTP API 端點強制執行 `TLS_1_2` 的安全政策。

*安全政策*是由 Amazon API Gateway 提供的最低 TLS 版本與密碼套件的預先定義組合。TLS 通訊協定可解決用戶端和伺服器間的竄改與竊聽等網路安全問題。當用戶端透過自訂網域建立 API 的 TLS 信號交換時，安全政策會強制執行用戶端可選擇使用的 TLS 版本和密碼套件。此安全政策接受 TLS 1.2 和 TLS 1.3 流量，並拒絕 TLS 1.0 流量。

## HTTP API 支援的 TLS 通訊協定和密碼
<a name="http-api-ciphers-list"></a>

下表說明 HTTP API 支援的 TLS 通訊協定。


| **TLS 通訊協定** | **TLS\$11\$12 安全政策** | 
| --- | --- | 
| TLSv1.3 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_tw/apigateway/latest/developerguide/images/success_icon.svg) 是 | 
| TLSv1.2 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_tw/apigateway/latest/developerguide/images/success_icon.svg) 是 | 

下表說明適用於 HTTP API 的 TLS 1\$12 安全政策的 TLS 加密。


| **TLS 加密** | **TLS\$11\$12 安全政策** | 
| --- | --- | 
| TLS-AES-128-GCM-SHA256 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_tw/apigateway/latest/developerguide/images/success_icon.svg) 是 | 
| TLS-AES-256-GCM-SHA384 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_tw/apigateway/latest/developerguide/images/success_icon.svg) 是 | 
| TLS-CHACHA20-POLY1305-SHA256 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_tw/apigateway/latest/developerguide/images/success_icon.svg) 是 | 
| ECDHE-ECDSA-AES128-GCM-SHA256 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_tw/apigateway/latest/developerguide/images/success_icon.svg) 是 | 
| ECDHE-RSA-AES128-GCM-SHA256 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_tw/apigateway/latest/developerguide/images/success_icon.svg) 是 | 
| ECDHE-ECDSA-AES128-SHA256 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_tw/apigateway/latest/developerguide/images/success_icon.svg) 是 | 
| ECDHE-RSA-AES128-SHA256 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_tw/apigateway/latest/developerguide/images/success_icon.svg) 是 | 
| ECDHE-ECDSA-AES256-GCM-SHA384 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_tw/apigateway/latest/developerguide/images/success_icon.svg) 是 | 
| ECDHE-RSA-AES256-GCM-SHA384 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_tw/apigateway/latest/developerguide/images/success_icon.svg) 是 | 
| ECDHE-ECDSA-AES256-SHA384 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_tw/apigateway/latest/developerguide/images/success_icon.svg) 是 | 
| ECDHE-RSA-AES256-SHA384 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_tw/apigateway/latest/developerguide/images/success_icon.svg) 是 | 
| AES128-GCM-SHA256 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_tw/apigateway/latest/developerguide/images/success_icon.svg) 是 | 
| AES128-SHA256 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_tw/apigateway/latest/developerguide/images/success_icon.svg) 是 | 
| AES256-GCM-SHA384 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_tw/apigateway/latest/developerguide/images/success_icon.svg) 是 | 
| AES256-SHA256 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_tw/apigateway/latest/developerguide/images/success_icon.svg) 是 | 

## OpenSSL 和 RFC 密碼名稱
<a name="apigateway-secure-connections-openssl-rfc-cipher-names-http"></a>

OpenSSL 和 IETF RFC 5246 使用相同密碼的不同名稱。如需密碼名稱的清單，請參閱 [OpenSSL 和 RFC 密碼名稱](apigateway-security-policies-list.md#apigateway-secure-connections-openssl-rfc-cipher-names)。

## REST API 和 WebSocket API 的相關資訊
<a name="apigateway-http-additional-apis"></a>

如需 REST API 和 WebSocket API 的詳細資訊，請參閱 [在 API Gateway 中為您的自訂網域選擇安全政策](apigateway-custom-domain-tls-version.md) 和 [API Gateway 中適用於 WebSocket API 的安全政策](websocket-api-ciphers.md)。

# API Gateway 中 HTTP API 的自訂網域名稱
<a name="http-api-custom-domain-names"></a>

*自訂網域名稱*是更簡單且更直觀的 URL，可提供給 API 使用者。

部署 API 之後，您 (和您的客戶) 可以使用下列格式的預設基本 URL 來呼叫 API：

```
https://api-id.execute-api.region.amazonaws.com/stage
```

其中 *api-id* 是 API Gateway 所產生，*region* 即為 (AWS 區域)，而 *stage* 是您在部署 API 時所指定。

URL 的主機名稱部分 (即 `api-id.execute-api.region.amazonaws.com`) 指的是 API 端點。預設 API 端點是隨機產生的，不容易取回，而且不方便使用。

使用自訂網域名稱，您就能設定 API 的主機名稱，並選擇基本路徑 (例如，`myservice`) 將替代 URL 映射至您的 API。例如，更方便使用者使用的 API 基本 URL 可以成為：

```
https://api.example.com/myservice
```

## 考量事項
<a name="http-api-custom-domain-name-considerations"></a>

下列考量事項可能會影響您使用自訂網域名稱。
+ 區域性自訂網域名稱可與 REST API 和 HTTP API 相關聯。您可以使用 API Gateway 第 2 版 API 來建立及管理 REST API 的區域性自訂網域名稱。
+ 對於最低 TLS 版本，僅 TLS 1.2 受支援。
+ 您必須建立或更新 DNS 提供者的資源記錄，以映射至您的 API 端點。如果沒有這種映射，送往自訂網域名稱的 API 請求無法到達 API Gateway。
+ 您可以使用萬用字元憑證來支援幾乎不限數量的網域名稱，而不會超過預設配額。如需更多詳細資訊，請參閱 [萬用字元自訂網域名稱](#http-wildcard-custom-domain-names)。

## 先決條件
<a name="http-api-custom-domain-names-prerequisites"></a>

以下是建立自訂網域名稱的先決條件。

### 註冊網域名稱
<a name="http-api-custom-domain-names-register"></a>

您必須具有已註冊的網際網路網域名稱，才能為您的 API 設定自訂網域名稱。您可以使用 [Amazon Route 53](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/) 或使用您選擇的第三方網域註冊機構來註冊網際網路網域。您的自訂網域名稱可以是已註冊網際網路網域的子網域或根網域 (也稱為 "zone apex") 的名稱。

您的網域名稱必須遵循 [RFC 1035](https://tools.ietf.org/html/rfc1035#section-2.3.4) 規格，每個標籤最多可有 63 個八位元組，總共有 255 個八位元組。

### 自訂網域名稱的憑證
<a name="http-api-custom-domain-names-certificates"></a>

必須為 API 設定自訂網域名稱前，您必須先在 ACM 中備妥 SSL/TLS 憑證。如果您建立自訂網域名稱的 AWS 區域中無法使用 ACM，則必須將憑證匯入該區域中的 API Gateway。

若要匯入 SSL/TLS 憑證，您必須提供 PEM 格式化 SSL/TLS 憑證內文、私有金鑰，以及自訂網域名稱的憑證鏈。

ACM 中所存放的每個憑證都是透過其 ARN 進行識別。使用 ACM 所發出的憑證，就不需要擔心公開任何敏感的憑證詳細資訊，例如私有金鑰。若要使用網域名稱的 AWS 受管憑證，您只需要參考其 ARN。

如果您的應用程式是使用憑證關聯 (有時稱為 SSL 關聯) 來關聯 ACM 憑證，則 AWS 續約憑證後，應用程式可能會無法連線到您的網域。如需詳細資訊，請參閱 *AWS Certificate Manager 使用者指南*中的[憑證關聯問題](https://docs.aws.amazon.com/acm/latest/userguide/troubleshooting-pinning.html)。

## 萬用字元自訂網域名稱
<a name="http-wildcard-custom-domain-names"></a>

使用萬用字元自訂網域名稱，您可以支援幾乎無限數目的網域名稱，而不會超過[預設配額](limits.md)。例如，您可以為每個客戶提供其自己的網域名稱，`customername.api.example.com`。

若要建立萬用字元自訂網域名稱，可以指定萬用字元 (`*`) 作為自訂網域的第一個子網域，藉以表示根網域所有可能的子網域。

例如，萬用字元自訂網域名稱 `*.example.com` 會產生如 `a.example.com`、`b.example.com` 和 `c.example.com` 等子網域，而這些子網域全都路由至相同的網域。

萬用字元自訂網域名稱支援來自 API Gateway 標準自訂網域名稱的相異組態。例如，您可以在單一 AWS 帳戶中，設定 `*.example.com` 和 `a.example.com` 採取不同的行為。

若要建立萬用字元自訂網域名稱，您必須提供由 ACM 發行並已經使用 DNS 或電子郵件驗證方法驗證的憑證。

**注意**  
如果不同的 AWS 帳戶已建立與萬用字元自訂網域名稱衝突的自訂網域名稱，則您無法建立萬用字元自訂網域名稱。例如，如果帳戶 A 已建立 `a.example.com`，則帳戶 B 無法建立萬用字元自訂網域名稱 `*.example.com`。  
如果帳戶 A 和帳戶 B 共用擁有者，您可以聯絡 [AWS 支援中心](https://console.aws.amazon.com/support/home#/)，以請求例外狀況。

## 自訂網域名稱的後續步驟
<a name="http-api-custom-domain-names-next-steps"></a>

若要設定 HTTP API 的自訂網域名稱，請參閱《API Gateway 開發人員指南》中的 REST API 相關章節文件。

首先，指定自訂網域名稱所用的憑證。如需更多詳細資訊，請參閱 [在 中備妥憑證 AWS Certificate Manager](how-to-specify-certificate-for-custom-domain-name.md)。接著，建立區域性自訂網域名稱。如需更多詳細資訊，請參閱 [在 API Gateway 中設定區域性自訂網域名稱](apigateway-regional-api-custom-domain-create.md)。

# 將 API 階段映射至 HTTP API 的自訂網域名稱
<a name="http-api-mappings"></a>

您可以使用 API 映射將 API 階段連線至自訂網域名稱。建立網域名稱並設定 DNS 記錄之後，您可以使用 API 映射，透過自訂網域名稱將流量傳送至您的 API。

API 映射指定一個 API，一個階段，以及選擇性用於映射的路徑。例如，您可以將 API 的 `production` 階段映射至 `https://api.example.com/orders`。

您可以將 HTTP 和 REST API 階段映射至相同的自訂網域名稱。

建立 API 映射之前，您必須先擁有 API、階段和自訂網域名稱。如需進一步了解如何建立自訂網域名稱，請參閱[在 API Gateway 中設定區域性自訂網域名稱](apigateway-regional-api-custom-domain-create.md)。

## 路由傳送 API 請求
<a name="http-api-mappings-evalutation"></a>

您可以設定具有多個層級的 API 映射，例如 `orders/v1/items` 和 `orders/v2/items`。

針對有多個層級的 API 映射，API Gateway 會將請求路由傳送至具有最長相符路徑的 API 映射。API Gateway 只會考慮為 API 映射而非 API 路由設定的路徑，以選取要調用的 API。如果沒有路徑與請求相符，則 API Gateway 會將請求傳送到您映射到空白路徑 `(none)` 的 API。

針對使用有多個層級的 API 映射的自訂網域名稱，API Gateway 會將請求路由傳送至具有最長相符字首的 API 映射。

例如，假設具有下列 API 映射的自訂網域名稱 `https://api.example.com`：

1. `(none)` 已映射到 API 1。

1. `orders` 已映射到 API 2。

1. `orders/v1/items` 已映射到 API 3。

1. `orders/v2/items` 已映射到 API 4。

1. `orders/v2/items/categories` 已映射到 API 5。


| 要求 | 選取的 API | 說明 | 
| --- | --- | --- | 
|  `https://api.example.com/orders`  |  `API 2`  |  請求完全符合此 API 映射。  | 
|  `https://api.example.com/orders/v1/items`  |  `API 3`  |  請求完全符合此 API 映射。  | 
|  `https://api.example.com/orders/v2/items`  |  `API 4`  |  請求完全符合此 API 映射。  | 
|  `https://api.example.com/orders/v1/items/123`  |  `API 3`  |  API Gateway 會選擇具有最長相符路徑的映射。請求結束時的 `123` 不會影響選擇。  | 
|  `https://api.example.com/orders/v2/items/categories/5`  |  `API 5`  |  API Gateway 會選擇具有最長相符路徑的映射。  | 
|  `https://api.example.com/customers`  |  `API 1`  |  API Gateway 使用空白映射作為全部擷取。  | 
|  `https://api.example.com/ordersandmore`  |  `API 2`  |  API Gateway 會選擇具有最長相符字首的映射。 針對設定使用單一層級映射的自訂網域名稱，例如只有 `https://api.example.com/orders` 和 `https://api.example.com/`，API Gateway 會選擇 `API 1`，因為沒有與 `ordersandmore` 相符的路徑。  | 

## 限制
<a name="http-api-mappings-restrictions"></a>
+ 在 API 映射中，自訂網域名稱和映射的 API 必須位於同一個 AWS 帳戶中。
+ API 映射只能包含字母、數字和下列字元：`$-_.+!*'()/`。
+ API 映射中路徑的最大長度為 300 個字元。
+ 您可以為每個域名設定具有 200 個具多個層級的 API 映射。此限制不包括具有單一層級的 API 映射，例如 `/prod`。
+ 您只能將 HTTP API 映射至具有 TLS 1.2 安全政策的區域自訂網域名稱。
+ 您無法將 WebSocket API 映射至與 HTTP API 或 REST API 相同的自訂網域名稱。
+ 如果您建立具有多層的 API 映射，API Gateway 會將所有標頭名稱轉換為小寫。

## 建立 API 映射
<a name="http-api-mappings-examples"></a>

若要建立 API 映射，您必須先建立自訂網域名稱、API 和階段。如需建立自訂網域名稱的資訊，請參閱[在 API Gateway 中設定區域性自訂網域名稱](apigateway-regional-api-custom-domain-create.md)。

有關建立所有資源的 AWS Serverless Application Model 範本範例，請參閱 GitHub 上的[使用 SAM 的工作階段](https://github.com/aws-samples/sessions-with-aws-sam/tree/master/custom-domains)。

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

**建立 API 映射**

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

1. 選擇 **Custom domain names** (自訂網域名稱)。

1. 選取您已建立的自訂網域名稱。

1. 選擇 **API mappings** (API 映射)。

1. 選擇 **Configure API mappings (設定 API 映射)**。

1. 選擇 **Add new mapping (新增映射)**。

1. 輸入 **API**、**Stage** (階段)，以及選擇性地輸入 **Path** (路徑)。

1. 選擇**儲存**。

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

以下 [create-api-mapping](https://docs.aws.amazon.com/cli/latest/reference/apigatewayv2/create-api.html) 命令會建立 API 映射。在此範例中，API Gateway 會將請求傳送至 `api.example.com/v1/orders`，到指定的 API 和階段。

```
aws apigatewayv2 create-api-mapping \
    --domain-name api.example.com \
    --api-mapping-key v1/orders \
    --api-id a1b2c3d4 \
    --stage test
```

------
#### [ CloudFormation ]

以下 CloudFormation 範例會建立 API 映射。

```
MyApiMapping:
  Type: 'AWS::ApiGatewayV2::ApiMapping'
  Properties:
    DomainName: api.example.com
    ApiMappingKey: 'orders/v2/items'
    ApiId: !Ref MyApi
    Stage: !Ref MyStage
```

------

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

預設情況下，用戶端可以使用 API Gateway 為 API 產生的 `execute-api` 端點來調用 API。若要確保用戶端只能使用自訂網域名稱來存取您的 API，請停用預設 `execute-api` 端點。當您停用預設端點時，它會影響 API 的所有階段。

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

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

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

1. 選擇一個 HTTP API。

1. 選擇 API 的 ID 以開啟 **API 詳細資訊**頁面。

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

1. 對於**預設端點**，選取**停用**。

1. 選擇**儲存**。

   如果您為階段開啟自動部署，則不需要為了讓變更生效而重新部署 API。否則，您必須重新部署 API。

1. (選用) 選擇**部署**，然後重新部署您的 API 或建立新的階段，以使變更生效。

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

以下 [update-domain-name](https://docs.aws.amazon.com/cli/latest/reference/apigatewayv2/update-domain-name.html) 命令會停用 HTTP API 的預設端點：

```
aws apigatewayv2 update-api \
    --api-id abcdef123 \
    --disable-execute-api-endpoint
```

停用預設端點後，您必須部署 API 才能讓變更生效，除非已啟用自動部署。

下列 [create-deployment](https://docs.aws.amazon.com/cli/latest/reference/apigatewayv2/create-deployment.html) 命令會建立部署：

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

------

# HTTP API 自訂網域名稱的 IP 位址類型
<a name="http-api-custom-domain-names-ip-address-type"></a>

建立 API 時，您可以指定可調用網域的 IP 位址類型。您可以選擇 IPv4 來解析 IPv4 位址以調用網域，也可以選擇雙堆疊，以同時允許 IPv4 和 IPv6 位址調用您的網域。我們建議您將 IP 位址類型設定為雙堆疊，以緩解 IP 空間耗盡或用於安全狀態。如需雙堆疊 IP 位址類型優點的詳細資訊，請參閱 [AWS 上的 IPv6](https://docs.aws.amazon.com/whitepapers/latest/ipv6-on-aws/internet-protocol-version-6.html)。

## IP 位址類型的考量事項
<a name="http-ip-address-type-considerations"></a>

下列考量事項可能會影響您使用 IP 位址類型。
+ API Gateway 自訂網域名稱的預設 IP 位址類型為 IPv4。
+ 您的自訂網域名稱不需要針對所有與其對應的 API 使用相同 IP 位址類型。如果您停用預設 API 端點，則可能會影響呼叫方調用 API 的方式。

## 變更自訂網域名稱的 IP 位址類型
<a name="http-api-custom-domain-names-ip-address-type-change"></a>

您可以藉由更新網域的端點組態來變更 IP 位址類型。您可以使用 AWS 管理主控台、AWS CLI、CloudFormation 或 AWS SDK 來更新網域的端點組態。

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

**若要變更自訂網域名稱的 IP 位址類型**

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

1. 選擇公有自訂網域名稱。

1. 選擇**端點組態**。

1. 針對 IP 位址類型，選取 **IPv4** 或**雙堆疊**。

1. 選擇**儲存**。

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

以下 [update-domain-name](https://docs.aws.amazon.com/cli/latest/reference/apigatewayv2/update-domain-name.html) 命令會將 API 更新為雙堆疊 IP 位址類型：

```
aws apigatewayv2 update-domain-name \
   --domain-name dualstack.example.com \
   --domain-name-configurations CertificateArn=arn:aws:acm:us-east-1:111122223333:certificate/abcd1234-5678-abc,IpAddressType=dualstack
```

輸出將如下所示：

```
{
    "ApiMappingSelectionExpression": "$request.basepath",
    "DomainName": "dualstack.example.com",
    "DomainNameConfigurations": [
        {
            "ApiGatewayDomainName": "d-abcd1234.execute-api.us-east-1.amazonaws.com",
            "CertificateArn": "arn:aws:acm:us-east-1:111122223333:certificate/abcd1234-5678-abc",
            "DomainNameStatus": "AVAILABLE",
            "EndpointType": "REGIONAL",
            "HostedZoneId": "Z3LQWSYCGH4ADY",
            "SecurityPolicy": "TLS_1_2",
            "IpAddressType": "dualstack"
        }
    ],
    "Tags": {}
}
```

------