Finding an Instance’s Endpoint

You can find the endpoint for an instance using the Amazon DocumentDB console or the AWS CLI.

Using the Console

To find an instance’s endpoint using the console

  1. Sign in to the AWS Management Console, and open the Amazon DocumentDB console at https://console.aws.amazon.com/docdb.

  2. In the navigation pane, choose Clusters.

    Tip

    If you don’t see the navigation pane on the left side of your screen, choose the menu icon (Finding an Instance’s Endpoint - 图1) in the upper-left corner of the page.

  3. In the Clusters navigation box, you’ll see the column Cluster Identifier. Your instances are listed under clusters, similar to the screenshot below.

    Finding an Instance’s Endpoint - 图2

  4. Check the box to the left of the instance you are interested in.

  5. Scroll down to the Details section then locate the instance endpoint.

    ![

    1. Console screenshot showing the details page with the instance endpoint highlighted.
    2. ](/projects/DocumentDB-20201111-en/492b3451d20044ee3d0a7a155588e85e.png)
  6. To connect to this instance, scroll up to the Connect section. Locate the connection string for the mongo shell and a connection string that can be used in your application code to connect to your instance.

    ![

    1. Console screenshot showing the connect section with mongo shell and application connection strings highlighted.
    2. ](https://docs.aws.amazon.com/documentdb/latest/developerguide/images/instance-connection-strings.png)

Using the AWS CLI

To find the instance endpoint using the AWS CLI, run the following command with these arguments.

Arguments

  • --db-instance-identifier—Optional. Specifies the instance to return the endpoint for. If omitted, returns the endpoint for up to 100 of your instances.

  • --query—Optional. Specifies the fields to display. Helpful by reducing the amount of data that you need to view to find the endpoints. If omitted, all information on an instance is returned. The Endpoint field has three members, so listing it in the query as in the following example returns all three members. If you’re only interested in some of the Endpoint members, replace Endpoint in the query with the members you’re interested in, as in the second example.

  • --region—Optional. Use the --region parameter to specify the Region that you want to apply the command to. If omitted, your default Region is used.

For Linux, macOS, or Unix:

  1. aws docdb describe-db-instances \
  2. --region us-east-1 \
  3. --db-instance-identifier sample-cluster-instance \
  4. --query 'DBInstances[*].[DBInstanceIdentifier,Endpoint]'

For Windows:

  1. aws docdb describe-db-instances ^
  2. --region us-east-1 ^
  3. --db-instance-identifier sample-cluster-instance ^
  4. --query 'DBInstances[*].[DBInstanceIdentifier,Endpoint]'

Output from this operation looks something like the following (JSON format).

  1. [
  2. [
  3. "sample-cluster-instance",
  4. {
  5. "Port": 27017,
  6. "Address": "sample-cluster-instance.corcjozrlsfc.us-east-1.docdb.amazonaws.com",
  7. "HostedZoneId": "Z2R2ITUGPM61AM"
  8. }
  9. ]
  10. ]

Reducing the output to eliminate the endpoint’s HostedZoneId, you can modify your query by specifying Endpoint.Port and Endpoint.Address.

For Linux, macOS, or Unix:

  1. aws docdb describe-db-instances \
  2. --region us-east-1 \
  3. --db-instance-identifier sample-cluster-instance \
  4. --query 'DBInstances[*].[DBInstanceIdentifier,Endpoint.Port,Endpoint.Address]'

For Windows:

  1. aws docdb describe-db-instances ^
  2. --region us-east-1 ^
  3. --db-instance-identifier sample-cluster-instance ^
  4. --query 'DBInstances[*].[DBInstanceIdentifier,Endpoint.Port,Endpoint.Address]'

Output from this operation looks something like the following (JSON format).

  1. [
  2. [
  3. "sample-cluster-instance",
  4. 27017,
  5. "sample-cluster-instance.corcjozrlsfc.us-east-1.docdb.amazonaws.com"
  6. ]
  7. ]

Now that you have the instance endpoint, you can connect to the instance using either mongo or mongodb. For more information, see Connecting to Endpoints.