Amazon DocumentDB cluster with Mongo connection from applicaiton failing

aws documentdb tutorial
connect to aws documentdb
aws documentdb sdk
aws documentdb public
aws documentdb nodejs
aws documentdb external access
documentdb connection timeout
aws documentdb create database

I am trying to set up an Amazon EB instance to work with DocumentDB. When I try to connect with amazon linux terminal, the connection just work fine. But when I try to connect with PHP it returns an error shown below

"No suitable servers found (serverSelectionTryOnceset): [socket timeout calling ismaster on 'docdb-XXXX-XX-XX-XX-XX-XX.cluster-cXXXXXXXXXX.eu-west-1.docdb.amazonaws.com:27017']"

I troubleshooted with terminal and got "succeeded!" which indicate successful connection again.

nc -zv docdb-docdb-XXXX-XX-XX-XX-XX-XX.cluster-cXXXXXXXXXX.eu-west-1.docdb.amazonaws.com 27017

Anyone has any idea what can be wrong?

Here is my code to connect to DocumentDB

$conn = new MongoClient("mongodb://username:password@docdb-docdb-XXXX-XX-XX-XX-XX-XX.cluster-cXXXXXXXXXX.eu-west-1.docdb.amazonaws.com:27017/?ssl_ca_certs=rds-combined-ca-bundle.pem&replicaSet=rs0");

In order for your PHP server to access DocumentDB your cluster must be in the same VPC. If your server is trying to connect from a different location, your authentication might fail.

https://docs.aws.amazon.com/documentdb/latest/developerguide/troubleshooting.html#troubleshooting.cannot-connect.public-endpoints

Also AWS does not support the latest MongoDB Drivers because they can't support the latest MongoDB API.

You can avoid both limitations by using MongoDB Atlas. You can deploy a MongoDB cluster in AWS in minutes and you would not be faced with the same limitations.

https://cloud.mongodb.com/

Resolve Problems Connecting to an Amazon DocumentDB Cluster, By default, TLS is enabled on Amazon DocumentDB clusters. how to connect to Amazon DocumentDB (with MongoDB compatibility) using several Following that, you can continue by finding and applying the appropriate code example. Fatalf("Failed to connect to cluster: %v", err) } // Force a connection to verify our� I am trying to set up an Amazon EB instance to work with DocumentDB. When I try to connect with amazon linux terminal, the connection just work fine. But when I try to connect with PHP it returns an

Try adding "ssl=true&" to your connection string. Please see below:

$conn = new MongoClient("mongodb://username:password@docdb-docdb-XXXX-XX-XX-XX-XX-XX.cluster-cXXXXXXXXXX.eu-west-1.docdb.amazonaws.com:27017/?ssl=true&ssl_ca_certs=rds-combined-ca-bundle.pem&replicaSet=rs0");

Connecting Programmatically to Amazon DocumentDB, In order for your PHP server to access DocumentDB your cluster must be in If your server is trying to connect from a different location, your authentication might fail. You can deploy a MongoDB cluster in AWS in minutes and you link you have given, it gives Success, But doesn't work with application. Amazon DocumentDB cluster with Mongo connection from applicaiton failing I am trying to set up an Amazon EB instance to work with DocumentDB. When I try to connect with amazon linux terminal, the connection just work fine.

You might want to try specifying a database name with the cluster. Something like: mongodb://username:password@docdb-docdb-XXXX-XX-XX-XX-XX-XX.cluster-cXXXXXXXXXX.eu-west-1.docdb.amazonaws.com:27017/proddb?ssl_ca_certs=rds-combined-ca-bundle.pem&replicaSet=rs0

What Is Amazon DocumentDB (with MongoDB Compatibility , Time to launch an Amazon DocumentDB Cluster. Note: Set Instance Class as connection attempt failed: SocketException: Error connecting to� to continue to Microsoft Azure. Email, phone, or Skype. No account? Create one!

Please see the following example.

Also, in your connection string it looks like you have an extra "docdb-", i.e., "docdb-docdb-XXXX-XX-XX-XX-XX-XX.cluster..."

<?php
require 'vendor/autoload.php'; // include Composer's autoloader

$SSL_DIR = "/home/ubuntu";
$SSL_FILE = "rds-combined-ca-bundle.pem";

$ctx = stream_context_create(array(
    "ssl" => array( 
        "cafile" => $SSL_DIR . "/" . $SSL_FILE,
    ))
);

$client = new MongoDB\Client("mongodb://<yourUserName>:<yourPassword>@docdb-2019-01-29-02-53-18.cluster-ccuszbx3pn5e.us-east-1.docdb.amazonaws.com:27017", array("ssl" => true), array("context" => $ctx));

$col = $client->test->col;

$result = $col->insertOne( [ 'hello' => 'Amazon DocumentDB'] );

$result = $col->findOne(array('hello' => 'Amazon DocumentDB'));

print_r($result);

?>

Amazon DocumentDB cluster with Mongo connection from , Your Application does not need to have any change other then configuration string. Mongo 3.6 Goal for this post is Quick walk through of Amazon Document DB service. I will be creating entire cluster and connecting to it using Mongo Client tool. PLEASE DO NOT Solving A Tree Problem � Anshul Garg� Pipe method keeps failing on the parent process; How to count the number of digits in Python? [duplicate] File Cleaning Service; Can't find symbol - method (generic method) In Android, how to invoke sun.misc.Unsafe methods using Java reflection? Deserialize Json.net JSON File directly to a C# dictionary type? Reset a Radio button inside a Radio

If you are behind firewall and maintains whitelist for network ports,then you should have to open port 27017 to connect to MongoDB cluster.

How to use AWS DocumentDB. Let's create an AWS DocumentDB , Amazon DocumentDB: Cloud Native Architecture . 5 Connecting to Amazon DocumentDB . When developing modern applications, document databases like MongoDB are a popular choice distributed across the cluster, thus isolating the blast radius of disk failures. Each segment is�

AWS DocumentDB (MongoDB Compatibility) walk through, Amazon DocumentDB is a NoSQL JSON document database service with a limited Applications written for MongoDB will need to be re-written to work with Amazon DocumentDB. Largest Atlas instance supports 128,000 concurrent connections. Typical failover of 5 seconds, failed reads and writes auto-retried, cluster�

[PDF] Getting Started with Amazon DocumentDB (with MongoDB, With Amazon DocumentDB, you can run the same application code and use quickly replace instances in the event of hardware failure, which results in a You should connect to your Amazon DocumentDB cluster using the�

Comparing Amazon DocumentDB and MongoDB,

Comments
  • Thanks for your answer. I am running DB and Server in the same VPC and when I troubleshoot connection with the link you have given, it gives Success, But doesn't work with application. Still no idea what has been happening.
  • This is almost accurate but you forgot to mention that you must download the ssl file using the following wget https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem and store it in the certs directory in Linux2 /etc/ssl and change the $SSL_DIR to point to that linux directory.