

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

# 啟用 Amazon RDS 資料 API
<a name="data-api.enabling"></a>

若要使用 Amazon RDS 資料 API (資料 API)，請為 Aurora 資料庫叢集將其啟用。您可以在建立或修改資料庫叢集時啟用資料 API。

**注意**  
 叢集是否可使用資料 API，取決於您的 Aurora 版本、資料庫引擎和 AWS 區域。對於較舊的 Aurora 版本，資料 API 僅適用於 Aurora Serverless v1 叢集。對於較新的 Aurora 版本，資料 API 適用於同時使用佈建和 Aurora Serverless v2 執行個體的叢集。若要檢查叢集是否可以使用資料 API，請參閱 [RDS 資料 API 的支援區域和 Aurora 資料庫引擎](Concepts.Aurora_Fea_Regions_DB-eng.Feature.Data_API.md)。

**Topics**
+ [建立資料庫時啟用 RDS 資料 API](#data-api.enabling.creating)
+ [在現有資料庫啟用 RDS 資料 API](#data-api.enabling.modifying)

## 建立資料庫時啟用 RDS 資料 API
<a name="data-api.enabling.creating"></a>

當您建立的是支援 RDS 資料 API (資料 API) 的資料庫時，您可以啟用此功能。下列程序說明如何在使用 AWS 管理主控台 AWS CLI、 或 RDS API 時執行此操作。

### 主控台
<a name="data-api.enabling.creating.console"></a>

如下列螢幕擷取畫面所示，若要在建立資料庫叢集時啟用資料 API，請選取**建立資料庫**頁面的**連線**區段中**啟用 RDS 資料 API** 核取方塊。

![\[[建立資料庫] 頁面上的 [連線] 區段，其中已選取 [啟用 RDS 資料 API] 核取方塊。\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/images/data-api-enable-on-create.png)


如需如何建立可使用 RDS 資料 API 的 Aurora 資料庫叢集的說明，請參閱下文：
+ 對於 Aurora Serverless v2 和佈建的叢集：[建立 Amazon Aurora 資料庫叢集](Aurora.CreateInstance.md)
+ 對於 Aurora Serverless v1：[建立 Aurora Serverless v1 資料庫叢集](aurora-serverless.create.md)

### AWS CLI
<a name="data-api.enabling.creating.cli"></a>

若要在建立 Aurora 資料庫叢集時啟用資料 API，請使用 `--enable-http-endpoint`選項執行 [create-db-cluster](https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-cluster.html) AWS CLI 命令。

下列範例會建立已啟用資料 API 的 Aurora PostgreSQL 資料庫叢集。

對於 Linux、macOS 或 Unix：

```
aws rds create-db-cluster \
    --db-cluster-identifier my_pg_cluster \
    --engine aurora-postgresql \
    --enable-http-endpoint
```

在 Windows 中：

```
aws rds create-db-cluster ^
    --db-cluster-identifier my_pg_cluster ^
    --engine aurora-postgresql ^
    --enable-http-endpoint
```

### RDS API
<a name="data-api.enabling.creating.api"></a>

若要在建立 Aurora 資料庫叢集時啟用資料 API，請使用 [CreateDBCluster](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBCluster.html) 操作，並將 `EnableHttpEndpoint` 參數的值設為 `true`。

## 在現有資料庫啟用 RDS 資料 API
<a name="data-api.enabling.modifying"></a>

您可以修改支援 RDS 資料 API (資料 API) 的資料庫叢集，即可啟用或停用此功能。

**Topics**
+ [啟用或停用資料 API (Aurora Serverless v2 和已佈建)](#data-api.enabling.modifying.all)
+ [啟用或停用資料 API (僅限 Aurora Serverless v1)](#data-api.enabling.modifying.sv1)

### 啟用或停用資料 API (Aurora Serverless v2 和已佈建)
<a name="data-api.enabling.modifying.all"></a>

使用下列程序啟用或停用 Aurora Serverless v2 和佈建資料庫的資料 API。若要啟用或停用在 Aurora Serverless v1 資料庫的資料 API，請使用 [啟用或停用資料 API (僅限 Aurora Serverless v1)](#data-api.enabling.modifying.sv1) 中的程序。

#### 主控台
<a name="data-api.enabling.modifying.all.console"></a>

您可以使用支援此功能之資料庫叢集的 RDS 主控台，來啟用或停用資料 API。若要這樣做，請開啟您要啟用或停用資料 API 之資料庫的叢集詳細資訊頁面，然後在**連線與安全**索引標籤，前往 **RDS 資料 API** 區段。本節顯示資料 API 的狀態，並允許您將其啟用或停用。

下列螢幕擷取畫面顯示未啟用的 **RDS 資料 API**。

![\[資料庫叢集詳細資訊頁面的 [連線和安全] 索引標籤上的 [RDS 資料 API] 區段。資料 API 的狀態會顯示為已停用，並且存在 [啟用 RDS 資料 API] 按鈕。\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/images/data-api-enable-from-details.png)


#### AWS CLI
<a name="data-api.enabling.modifying.all.cli"></a>

若要啟用或停用現有資料庫上的資料 API，請執行 [enable-http-endpoint](https://docs.aws.amazon.com/cli/latest/reference/rds/enable-http-endpoint.html) 或 [disable-http-endpoint](https://docs.aws.amazon.com/cli/latest/reference/rds/disable-http-endpoint.html) AWS CLI 命令，並指定資料庫叢集的 ARN。

下列範例會啟用資料 API。

對於 Linux、macOS 或 Unix：

```
aws rds enable-http-endpoint \
    --resource-arn cluster_arn
```

在 Windows 中：

```
aws rds enable-http-endpoint ^
    --resource-arn cluster_arn
```

#### RDS API
<a name="data-api.enabling.modifying.all.api"></a>

若要啟用或停用現有資料庫上的資料 API，請使用 [EnableHttpEndpoint](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_EnableHttpEndpoint.html) 和 [DisableHttpEndpoint](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_DisableHttpEndpoint.html) 操作。

### 啟用或停用資料 API (僅限 Aurora Serverless v1)
<a name="data-api.enabling.modifying.sv1"></a>

使用下列程序來啟用或停用現有 Aurora Serverless v1 資料庫的資料 API。若要在 Aurora Serverless v2 和佈建的資料庫啟用或停用資料 API，請使用 [啟用或停用資料 API (Aurora Serverless v2 和已佈建)](#data-api.enabling.modifying.all) 中的程序。

#### 主控台
<a name="data-api.enabling.modifying.sv1.console"></a>

修改 Aurora Serverless v1 資料庫叢集時，在 RDS 主控台的**連線** 區段中啟用資料 API。

下列螢幕擷取畫面顯示修改 Aurora DB 資料庫叢集時啟用的**資料 API**。

![\[[修改資料庫叢集] 頁面上的 [連線] 區段，已選取 [資料 API] 核取方塊。\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/images/data-api-modify-serverlessv1.png)


如需如何修改 Aurora Serverless v1 資料庫叢集的指示，請參閱[修改 Aurora Serverless v1 資料庫叢集](aurora-serverless.modifying.md)。

#### AWS CLI
<a name="data-api.enabling.modifying.sv1.cli"></a>

若要啟用或停用資料 API，`--no-enable-http-endpoint`請視需要使用 `--enable-http-endpoint`或 執行 [modify-db-cluster](https://docs.aws.amazon.com/cli/latest/reference/rds/modify-db-cluster.html) AWS CLI 命令。

下列範例會在 `sample-cluster` 啟用資料 API。

對於 Linux、macOS 或 Unix：

```
aws rds modify-db-cluster \
    --db-cluster-identifier sample-cluster \
    --enable-http-endpoint
```

在 Windows 中：

```
aws rds modify-db-cluster ^
    --db-cluster-identifier sample-cluster ^
    --enable-http-endpoint
```

#### RDS API
<a name="data-api.enabling.modifying.sv1.api"></a>

若要啟用資料 API，請使用 [ModifyDBCluster](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_ModifyDBCluster.html) 操作，以及視需要將 `EnableHttpEndpoint` 的值設為 `true` 或 `false`。