

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 查找实例的端点
<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/zh_cn/documentdb/latest/developerguide/images/docdb-menu-icon.png))。

1. 在集群导航框中，您将看到“**集群标识符**”列。您的实例列于集群下，类似于以下屏幕截图。  
![\[“集群”表显示了“集群标识符”列下的集群列表，其中实例嵌套在集群内。\]](http://docs.aws.amazon.com/zh_cn/documentdb/latest/developerguide/images/choose-clusters.png)

1. 选中您感兴趣的实例左侧的框。

1. 向下滚动至 **Details (详细信息)** 部分，然后找到实例终端节点。  
![\[控制台屏幕截图显示了突出显示实例端点的详情页面。\]](http://docs.aws.amazon.com/zh_cn/documentdb/latest/developerguide/images/db-instance-endpoint.png)

1. 要连接到这个实例，请向上滚动到**连接**部分。定位 `mongo` Shell 的连接字符串和一个可在应用程序代码中用来连接到您实例的连接字符串。  
![\[控制台屏幕截图显示了突出显示 mongo Shell 和应用程序连接字符串的“连接”部分。\]](http://docs.aws.amazon.com/zh_cn/documentdb/latest/developerguide/images/instance-connection-strings.png)

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

要使用 AWS CLI 查找实例终端节点，请运行带有以下参数的命令。

**参数**
+ **--db-instance-identifier**—可选。指定要返回端点的实例。如果省略， 将返回多达 100 个实例的端点。
+ **--query**—可选。指定要显示的字段。因减少您为查找端点所需查看的数据量而有益。如果省略，则返回有关实例的所有信息。`Endpoint` 字段有三个成员，因此在查询中列出它则返回所有三个成员，如下例所示。如果您只对部分 `Endpoint` 成员感兴趣，请将查询中的 `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)。

------