

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# Amazon DocumentDB エンドポイントについて
<a name="endpoints"></a>

Amazon DocumentDB (MongoDB 互換) エンドポイントを使用して、クラスターまたはインスタンスに接続できます。Amazon DocumentDB には 3 つの異なる種類のエンドポイントがあり、それぞれに独自の用途があります。

**Topics**
+ [クラスターのエンドポイントの検索](db-cluster-endpoints-find.md)
+ [インスタンスのエンドポイントの検索](db-instance-endpoint-find.md)
+ [エンドポイントへの接続](endpoints-connecting.md)

**クラスターエンドポイント**  
クラスターエンドポイントとは、クラスターの現在のプライマリインスタンスに接続する Amazon DocumentDB のクラスターのエンドポイントです。Amazon DocumentDB クラスターごとに 1 つのクラスターエンドポイントと 1 つのプライマリインスタンスがあります。フェイルオーバーが発生すると、クラスターエンドポイントは新しいプライマリインスタンスに再マッピングされます。

**リーダーエンドポイント**  
読み取りエンドポイントとは、そのクラスターで利用できるレプリカの 1 つに接続する、Amazon DocumentDB クラスターのエンドポイントです。各 Amazon DocumentDB クラスターに読み取りエンドポイントがあります。複数のレプリカがある場合、読み取りエンドポイントは各接続リクエストを Amazon DocumentDB レプリカのいずれかにルーティングします。

**インスタンスエンドポイント**  
インスタンスエンドポイントは、特定のインスタンスに接続するエンドポイントです。クラスターの各インスタンスには、プライマリインスタンスかレプリカインスタンスタイプにかかわらず、独自のインスタンスエンドポイントがあります。アプリケーションでインスタンスエンドポイントを使用しないことが推奨されます。これは、フェイルオーバーの場合にインスタンスエンドポイントがロールを変更することがあり、これによってアプリケーション内のコード変更が必要となるためです。

# クラスターのエンドポイントの検索
<a name="db-cluster-endpoints-find"></a>

Amazon DocumentDB コンソールまたは AWS CLI を使用して、クラスターのクラスターエンドポイントと読み込みエンドポイントを見つけることができます。

------
#### [ Using the AWS マネジメントコンソール ]

**コンソールを使用してクラスターのエンドポイントを見つけるには:**

1. AWS マネジメントコンソール にサインインして、Amazon DocumentDB コンソール [https://console.aws.amazon.com/docdb](https://console.aws.amazon.com/docdb) を開いてください。

1. ナビゲーションペインで [**クラスター**] を選択します。

1. クラスターの一覧で、関心のあるクラスターの名前を選択します。

1. クラスターの詳細ページで、**[Configuration]** (構成) タブを選択します。**設定およびステータス** セクションには、**クラスターエンドポイント** と **リーダーエンドポイント** があります。  
![\[クラスターとリーダーエンドポイントを示す設定およびステータスセクション。\]](http://docs.aws.amazon.com/ja_jp/documentdb/latest/developerguide/images/db-cluster-endpoints.png)

1. このクラスターに接続するには、[**接続とセキュリティ**] タブを選択します。`mongo` シェルの接続文字列と、アプリケーションコードで使用してクラスターに接続できる接続文字列を見つけます。  
![\[mongo シェルを使用してインスタンスに接続する文字列と、アプリケーションを使用してクラスターに接続する文字列を示す接続セクション。\]](http://docs.aws.amazon.com/ja_jp/documentdb/latest/developerguide/images/cluster-connection-strings.png)

------
#### [ Using the AWS CLI ]

AWS CLI を使用してクラスターと読み込みエンドポイントを見つけるには、以下のパラメータを指定して `describe-db-clusters` コマンドを実行します。

**パラメータ**
+ **--db-cluster-identifier** - オプションです。エンドポイントを返すクラスターを指定します。省略した場合、最大 100 個のクラスターのエンドポイントを返します。
+ **--query** - オプションです。表示するフィールドを指定します。エンドポイントを見つけるために表示する必要があるデータの量を減らすと役立ちます。省略した場合、すべてのクラスターについての情報が返されます。
+ **--region** - オプションです。`--region` パラメータを使用して、コマンドを適用するリージョンを指定します。省略すると、デフォルトのリージョンが使用されます。

**Example**  
次の例では、`DBClusterIdentifier`、エンドポイント (クラスターエンドポイント)、および `ReaderEndpoint` の `sample-cluster` を返します。  
Linux、macOS、Unix の場合:  

```
aws docdb describe-db-clusters \
   --region us-east-1 \
   --db-cluster-identifier sample-cluster \
   --query 'DBClusters[*].[DBClusterIdentifier,Port,Endpoint,ReaderEndpoint]'
```
Windows の場合:  

```
aws docdb describe-db-clusters ^
   --region us-east-1 ^
   --db-cluster-identifier sample-cluster ^
   --query 'DBClusters[*].[DBClusterIdentifier,Port,Endpoint,ReaderEndpoint]'
```
このオペレーションによる出力は、次のようになります（JSON 形式）。  

```
[
  [
     "sample-cluster",
     27017,
     "sample-cluster.cluster-corlsfccjozr.us-east-1.docdb.amazonaws.com",
     "sample-cluster.cluster-ro-corlsfccjozr.us-east-1.docdb.amazonaws.com"
  ]
]
```

これでクラスターエンドポイントが作成したので、`mongo` または `mongodb` を使用してクラスターに接続できます。詳細については、「[エンドポイントへの接続](endpoints-connecting.md)」を参照してください。

------

# インスタンスのエンドポイントの検索
<a name="db-instance-endpoint-find"></a>

Amazon DocumentDB コンソールまたは AWS CLI を使用して、インスタンスのためのエンドポイントを見つけることができます。

------
#### [ Using the AWS マネジメントコンソール ]

**コンソールを使用してインスタンスのエンドポイントを見つけるには**

1. AWS マネジメントコンソール にサインインして、Amazon DocumentDB コンソール [https://console.aws.amazon.com/docdb](https://console.aws.amazon.com/docdb) を開いてください。

1. ナビゲーションペインで [**クラスター**] を選択します。
**ヒント**  
画面の左側にナビゲーションペインが表示されない場合は、ページの左上隅にあるメニューアイコン (![\[Hamburger menu icon with three horizontal lines.\]](http://docs.aws.amazon.com/ja_jp/documentdb/latest/developerguide/images/docdb-menu-icon.png)) を選択します。

1. クラスターナビゲーションボックスに、[**Cluster Identifier**]の列が表示されます。インスタンスは、以下のスクリーンショットのように、クラスターの下に表示されます。  
![\[インスタンスがクラスター内にネストされている、クラスター識別子列の下のクラスターのリストを示すクラスターテーブル。\]](http://docs.aws.amazon.com/ja_jp/documentdb/latest/developerguide/images/choose-clusters.png)

1. 興味があるインスタンスの左側にあるチェックボックスをチェックします。

1. [**詳細**] セクションまで下にスクロールし、インスタンスのエンドポイントを見つけます。  
![\[インスタンスのエンドポイントが強調表示された詳細ページを示しているコンソールのスクリーンショット。\]](http://docs.aws.amazon.com/ja_jp/documentdb/latest/developerguide/images/db-instance-endpoint.png)

1. このインスタンスに接続するには、[**接続**] セクションまで上にスクロールします。`mongo` シェルの接続文字列と、アプリケーションコードで使用してインスタンスに接続できる接続文字列を見つけます。  
![\[mongo シェルとアプリケーションの接続文字列が強調表示された、[接続] セクションを表示しているコンソールのスクリーンショット。\]](http://docs.aws.amazon.com/ja_jp/documentdb/latest/developerguide/images/instance-connection-strings.png)

------
#### [ Using the AWS CLI ]

AWS CLI を使用してインスタンスのエンドポイントを見つけるには、以下の引数を使用して以下のコマンドを実行します。

**引数**
+ **--db-instance-identifier** - オプションです。エンドポイントを返すインスタンスを指定します。省略した場合、最大 100 個のインスタンスのエンドポイントを返します。
+ **--query** - オプションです。表示するフィールドを指定します。エンドポイントを見つけるために表示する必要があるデータの量を減らすと役立ちます。省略した場合、インスタンスのすべての情報が返されます。この `Endpoint` フィールドには 3 つのメンバーがあるため、次の例に示すようにクエリでリストすると、3 つすべてのメンバーが返されます。一部の `Endpoint` メンバーのみに関心がある場合は、2 番目の例のように、クエリで `Endpoint` を関心のあるメンバーに置き換えます。
+ **--region** - オプションです。`--region` パラメータを使用して、コマンドを適用するリージョンを指定します。省略すると、デフォルトのリージョンが使用されます。

**Example**  
Linux、macOS、Unix の場合:  

```
aws docdb describe-db-instances \
    --region us-east-1 \
    --db-instance-identifier sample-cluster-instance \
    --query 'DBInstances[*].[DBInstanceIdentifier,Endpoint]'
```
Windows の場合:  

```
aws docdb describe-db-instances ^
    --region us-east-1 ^
    --db-instance-identifier sample-cluster-instance ^
    --query 'DBInstances[*].[DBInstanceIdentifier,Endpoint]'
```
このオペレーションによる出力は、次のようになります (JSON 形式)。  

```
[
    [
        "sample-cluster-instance",
        {
            "Port": 27017,
            "Address": "sample-cluster-instance.corcjozrlsfc.us-east-1.docdb.amazonaws.com",
            "HostedZoneId": "Z2R2ITUGPM61AM"
        }
    ]
]
```
出力を減らしてエンドポイントの `HostedZoneId` を排除すると、`Endpoint.Port` と `Endpoint.Address` を使用してクエリを変更することができます。  
Linux、macOS、Unix の場合:  

```
aws docdb describe-db-instances \
    --region us-east-1 \
    --db-instance-identifier sample-cluster-instance \
    --query 'DBInstances[*].[DBInstanceIdentifier,Endpoint.Port,Endpoint.Address]'
```
Windows の場合:  

```
aws docdb describe-db-instances ^
    --region us-east-1 ^
    --db-instance-identifier sample-cluster-instance ^
    --query 'DBInstances[*].[DBInstanceIdentifier,Endpoint.Port,Endpoint.Address]'
```
このオペレーションによる出力は、次のようになります (JSON 形式)。  

```
[
    [
        "sample-cluster-instance",
        27017,
        "sample-cluster-instance.corcjozrlsfc.us-east-1.docdb.amazonaws.com"
    ]
]
```

これでインスタンスエンドポイントを作成したので、`mongo` または `mongodb` を使用してインスタンスに接続できます。詳細については、「[エンドポイントへの接続](endpoints-connecting.md)」を参照してください。

------

# エンドポイントへの接続
<a name="endpoints-connecting"></a>

エンドポイント (クラスターまたはインスタンス) が作成されたら、`mongo` シェルまたは接続文字列を使用して接続できます。

## mongo シェルを使用した接続
<a name="endpoints-connecting-mongo"></a>

以下の構造を使用して、`mongo` シェルを使ってクラスターまたはインスタンスに接続する必要がある文字列を作成します。

```
mongo \
    --ssl \
    --host Endpoint:Port \
    --sslCAFile global-bundle.pem \
    --username UserName \
    --password Password
```

**`mongo` シェルの例**  
クラスターへの接続:

```
mongo \
    --ssl \
    --host sample-cluster.corcjozrlsfc.us-east-1.docdb.amazonaws.com:27017 \
    --sslCAFile global-bundle.pem \
    --username UserName \
    --password Password
```

インスタンスへの接続:

```
mongo \
    --ssl \
    --host sample-cluster-instance.corcjozrlsfc.us-east-1.docdb.amazonaws.com:27017 \
    --sslCAFile global-bundle.pem \
    --username UserName \
    --password Password
```

## 接続文字列を使用した接続
<a name="endpoints-connecting-mongodb"></a>

以下の構造を使用して、クラスターまたはインスタンスに接続する必要がある接続文字列を作成します。

```
mongodb://UserName:Password@endpoint:port?replicaSet=rs0&ssl_ca_certs=global-bundle.pem 
```

**接続文字列の例**  
クラスターへの接続:

```
mongodb://UserName:Password@sample-cluster.cluster-corlsfccjozr.us-east-1.docdb.amazonaws.com:27017?replicaSet=rs0&ssl_ca_certs=global-bundle.pem 
```

インスタンスへの接続:

```
mongodb://UserName:Password@sample-cluster-instance.cluster-corlsfccjozr.us-east-1.docdb.amazonaws.com:27017?replicaSet=rs0&ssl_ca_certs=global-bundle.pem 
```

 