

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

# 將自訂網域名稱遷移至 API Gateway 中不同的 API 端點
<a name="apigateway-regional-api-custom-domain-migrate"></a>

 您可以在邊緣最佳化與區域端點之間遷移自訂網域名稱。您無法將公有自訂網域名稱遷移至私有自訂網域名稱。您會先將新的端點組態類型新增至自訂網域名稱的現有 `endpointConfiguration.types` 清單。接著，您設定 DNS 記錄，以將自訂網域名稱指向新佈建的端點。最後，移除過時的自訂網域名稱端點。

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

以下是在區域 API 端點和邊緣最佳化的 API 端點之間移轉自訂網域的考量：
+ 邊緣最佳化的自訂網域名稱需要由美國東部 (維吉尼亞北部) – `us-east-1` 區域的 ACM 所提供的憑證。此憑證會分發至所有地理位置。
+ 區域性自訂網域名稱需要由託管 API 的相同區域中的 ACM 所提供的憑證。您可以將不在 `us-east-1` 區域中的邊緣最佳化的自訂網域名稱，遷移至區域性自訂網域名稱，方法是請求來自 API 本端區域的新 ACM 憑證。
+ 這可能需要最多 60 秒的時間才能完成邊緣最佳化的自訂網域名稱與區域性自訂網域名稱之間的遷移。遷移時間也取決於您何時更新 DNS 記錄。
+ 只有在端點存取模式設定為 時，您才能新增額外的端點組態`BASIC`。一旦您有兩個端點組態，就無法變更端點存取模式。如需詳細資訊，請參閱[端點存取模式](apigateway-security-policies.md#apigateway-security-policies-endpoint-access-mode)。
+ 如果您的自訂網域名稱使用開頭為 的安全政策`SecurityPolicy_`，當您新增新的端點組態類型時，兩個端點類型的端點存取模式都相同，而且您必須為新的端點組態類型選擇開頭`SecurityPolicy_`為 的安全政策。

## 遷移自訂網域名稱
<a name="apigateway-api-custom-domain-names-migrate-procedure"></a>

**注意**  
若要完成移轉，請務必從自訂網域名稱中移除過時的端點。

以下程序顯示如何將邊緣最佳化的自訂網域名稱遷移至區域性自訂網域。

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

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

1. 從主要導覽窗格中，選擇 **Custom Domain Names (自訂網域名稱)**。

1. 選擇邊緣最佳化的自訂網域名稱。

1. 針對**端點組態**，選擇**編輯**。

1. 選擇**新增區域端點**。

1. 針對 **ACM 憑證**，選擇憑證。

   區域憑證必須在與區域 API 相同的區域。

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

1. 設定 DNS 記錄，以將區域性自訂網域名稱指向此區域性主機名稱。如需詳細資訊，請參閱[設定 Route 53 以將流量轉送至 API Gateway](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-to-api-gateway.html)。

1. 確認 DNS 組態使用正確的端點後，您即可刪除邊緣最佳化的端點組態。選擇您的自訂網域名稱，然後針對**邊緣最佳化的端點組態**，選擇**刪除**。

1. 確認您的選擇並刪除端點。

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

以下 [update-domain-name](https://docs.aws.amazon.com/cli/latest/reference/apigateway/update-domain-name.html) 命令會將邊緣最佳化的自訂網域名稱移轉至區域自訂網域名稱：

```
aws apigateway update-domain-name \
    --domain-name 'api.example.com' \
    --patch-operations  '[ 
        { "op":"add", "path": "/endpointConfiguration/types","value": "REGIONAL" },
        { "op":"add", "path": "/regionalCertificateArn", "value": "arn:aws:acm:us-west-2:123456789012:certificate/cd833b28-58d2-407e-83e9-dce3fd852149" }
      ]'
```

區域憑證必須與區域 API 位在相同的區域。

輸出將如下所示：

```
{
    "certificateArn": "arn:aws:acm:us-east-1:123456789012:certificate/34a95aa1-77fa-427c-aa07-3a88bd9f3c0a",
    "certificateName": "edge-cert",
    "certificateUploadDate": "2017-10-16T23:22:57Z",
    "distributionDomainName": "d1frvgze7vy1bf.cloudfront.net",
    "domainName": "api.example.com",
    "endpointConfiguration": {
        "types": [
            "EDGE",
            "REGIONAL"
        ]
    },
    "regionalCertificateArn": "arn:aws:acm:us-west-2:123456789012:certificate/cd833b28-58d2-407e-83e9-dce3fd852149",
    "regionalDomainName": "d-fdisjghyn6.execute-api.us-west-2.amazonaws.com"
}
```

針對已遷移的區域自訂網域名稱，產生的 `regionalDomainName` 屬性會傳回區域 API 主機名稱。您必須設定 DNS 記錄，將區域自訂網域名稱指向此區域主機名稱。如此可讓繫結至自訂網域名稱的流量路由至區域主機。

設定 DNS 記錄之後，您可以將邊緣最佳化的自訂網域名稱移除。以下 [update-domain-name](https://docs.aws.amazon.com/cli/latest/reference/apigateway/update-domain-name.html) 命令會移除邊緣最佳化的自訂網域名稱：

```
aws apigateway update-domain-name \
    --domain-name api.example.com \
    --patch-operations '[
            {"op":"remove", "path":"/endpointConfiguration/types", "value":"EDGE"},
            {"op":"remove", "path":"certificateName"},
            {"op":"remove", "path":"certificateArn"}
        ]'
```

------

下列程序說明如何將使用增強型安全政策的邊緣最佳化自訂網域名稱遷移至也使用增強型安全政策的區域性自訂網域名稱。

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

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

1. 從主要導覽窗格中，選擇 **Custom Domain Names (自訂網域名稱)**。

1. 選擇邊緣最佳化的自訂網域名稱。

1. 針對**端點組態**，選擇**編輯**。

1. 選擇**新增區域端點**。

1. 針對 **ACM 憑證**，選擇憑證。

   區域憑證必須在與區域 API 相同的區域。

1. 針對**安全政策**，選擇開頭為 的安全政策`SecurityPolicy_`。

1. 針對**端點存取模式**，選擇**基本**。

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

1. 設定 DNS 記錄，以將區域性自訂網域名稱指向此區域性主機名稱。如需詳細資訊，請參閱[設定 Route 53 以將流量轉送至 API Gateway](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-to-api-gateway.html)。

1. 確認 DNS 組態使用正確的端點後，您即可刪除邊緣最佳化的端點組態。選擇您的自訂網域名稱，然後針對**邊緣最佳化的端點組態**，選擇**刪除**。

1. 確認您的選擇並刪除端點。

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

以下 [update-domain-name](https://docs.aws.amazon.com/cli/latest/reference/apigateway/update-domain-name.html) 命令會將邊緣最佳化的自訂網域名稱移轉至區域自訂網域名稱：

```
aws apigateway update-domain-name \
    --domain-name 'api.example.com' \
    --patch-operations  '[ 
        { "op":"add", "path": "/endpointConfiguration/types","value": "REGIONAL" },
        { "op":"replace", "path": "/securityPolicy", "value":"SecurityPolicy_TLS13_1_3_2025_09"},
        { "op":"add", "path": "/regionalCertificateArn", "value": "arn:aws:acm:us-west-2:123456789012:certificate/cd833b28-58d2-407e-83e9-dce3fd852149" }
      ]'
```

區域憑證必須與區域 API 位在相同的區域。

輸出將如下所示：

```
{
    "certificateArn": "arn:aws:acm:us-east-1:123456789012:certificate/34a95aa1-77fa-427c-aa07-3a88bd9f3c0a",
    "certificateName": "edge-cert",
    "certificateUploadDate": "2017-10-16T23:22:57Z",
    "distributionDomainName": "d1frvgze7vy1bf.cloudfront.net",
    "domainName": "api.example.com",
    "endpointConfiguration": {
        "types": [
            "EDGE",
            "REGIONAL"
        ]
    },
    "securityPolicy": "SecurityPolicy_TLS13_1_3_2025_09",
    "endpointAccessMode": "BASIC",
    "regionalCertificateArn": "arn:aws:acm:us-west-2:123456789012:certificate/cd833b28-58d2-407e-83e9-dce3fd852149",
    "regionalDomainName": "d-fdisjghyn6.execute-api.us-west-2.amazonaws.com"
}
```

針對已遷移的區域自訂網域名稱，產生的 `regionalDomainName` 屬性會傳回區域 API 主機名稱。您必須設定 DNS 記錄，將區域自訂網域名稱指向此區域主機名稱。如此可讓繫結至自訂網域名稱的流量路由至區域主機。

設定 DNS 記錄之後，您可以將邊緣最佳化的自訂網域名稱移除。以下 [update-domain-name](https://docs.aws.amazon.com/cli/latest/reference/apigateway/update-domain-name.html) 命令會移除邊緣最佳化的自訂網域名稱：

```
aws apigateway update-domain-name \
    --domain-name api.example.com \
    --patch-operations '[
            {"op":"remove", "path":"/endpointConfiguration/types", "value":"EDGE"},
            {"op":"remove", "path":"certificateName"},
            {"op":"remove", "path":"certificateArn"}
        ]'
```

------

以下程序顯示如何將區域性自訂網域名稱遷移至邊緣最佳化的自訂網域名稱。

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

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

1. 在主要導覽窗格中，選擇**自訂網域名稱**。

1. 選擇區域性自訂網域名稱。

1. 針對**端點組態**，選擇**編輯**。

1. 選擇**新增邊緣最佳化端點**。

1. 針對 **ACM 憑證**，選擇憑證。

    在 `us-east-1` 區域中，必須建立邊緣最佳化網域憑證。

1. 選擇**儲存**。

1. 設定 DNS 記錄，將邊緣最佳化的自訂網域名稱指向此邊緣最佳化的主機名稱。如需詳細資訊，請參閱[設定 Route 53 以將流量轉送至 API Gateway](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-to-api-gateway.html)。

1. 確認 DNS 組態使用正確的端點後，您就會刪除區域性端點組態。選擇您的自訂網域名稱，然後針對**區域性端點組態**，選擇**刪除**。

1. 確認您的選擇並刪除端點。

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

以下 [update-domain-name](https://docs.aws.amazon.com/cli/latest/reference/apigateway/update-domain-name.html) 命令會將區域自訂網域名稱移轉至邊緣最佳化的自訂網域名稱：

```
aws apigateway update-domain-name \
    --domain-name 'api.example.com' \
    --patch-operations  '[ 
        { "op":"add", "path": "/endpointConfiguration/types","value": "EDGE" },
        { "op":"add", "path": "/certificateName", "value": "edge-cert" },
	{"op":"add", "path": "/certificateArn", "value": "arn:aws:acm:us-east-1:738575810317:certificate/34a95aa1-77fa-427c-aa07-3a88bd9f3c0a"}
      ]'
```

在 `us-east-1` 區域中，必須建立邊緣最佳化網域憑證。

輸出將如下所示：

```
{
    "certificateArn": "arn:aws:acm:us-east-1:738575810317:certificate/34a95aa1-77fa-427c-aa07-3a88bd9f3c0a",
    "certificateName": "edge-cert",
    "certificateUploadDate": "2017-10-16T23:22:57Z",
    "distributionDomainName": "d1frvgze7vy1bf.cloudfront.net",
    "domainName": "api.example.com",
    "endpointConfiguration": {
        "types": [
            "EDGE",
            "REGIONAL"
        ]
    },
    "regionalCertificateArn": "arn:aws:acm:us-east-1:123456789012:certificate/3d881b54-851a-478a-a887-f6502760461d",
    "regionalDomainName": "d-cgkq2qwgzf.execute-api.us-east-1.amazonaws.com"
}
```

針對指定的自訂網域名稱，API Gateway 會傳回邊緣最佳化 API 主機名稱做為 `distributionDomainName` 屬性值。您必須設定 DNS 記錄，將邊緣最佳化自訂網域名稱指向此分佈網域名稱。如此可讓繫結至邊緣最佳化自訂網域名稱的流量路由至邊緣最佳化 API 主機名稱。

設定 DNS 記錄之後，您可以移除自訂網域名稱的 `REGION` 端點類型。以下 [update-domain-name](https://docs.aws.amazon.com/cli/latest/reference/apigateway/update-domain-name.html) 命令會移除區域端點類型：

```
aws apigateway update-domain-name \
    --domain-name api.example.com \
    --patch-operations '[
        {"op":"remove", "path":"/endpointConfiguration/types", value:"REGIONAL"},
        {"op":"remove", "path":"regionalCertificateArn"}
      ]'
```

輸出看起來如下：

```
{
    "certificateArn": "arn:aws:acm:us-east-1:738575810317:certificate/34a95aa1-77fa-427c-aa07-3a88bd9f3c0a",
    "certificateName": "edge-cert",
    "certificateUploadDate": "2017-10-16T23:22:57Z",
    "distributionDomainName": "d1frvgze7vy1bf.cloudfront.net",
    "domainName": "api.example.com",
    "endpointConfiguration": {
        "types": "EDGE"
    }
}
```

------