Unable to connect to AWS Docdb

269 Views Asked by At

We are trying to connect to aws docdb from errbit, but of no luck. This is the connection string from docdb:

mongodb://user:<insertYourPassword>@dev-docdb-cluster.cluster-xxxx.us-east-1.docdb.amazonaws.com:27017/?ssl=true&ssl_ca_certs=rds-combined-ca-bundle.pem&replicaSet=rs0

We are able to connect to Atlas db though, the connection string format we are using for atlas is something like this:

mongodb://user:[email protected]:27017,cluster-shard-00-01-xxx.mongodb.net:27017,cluster-shard-00-02-xxx.mongodb.net:27017/errbit?ssl=true&replicaSet=Cluster-shard-0&authSource=admin&w=majority
1

There are 1 best solutions below

2
On

You will need to change config/mongo.rb file to be as follows:

log_level = Logger.const_get Errbit::Config.log_level.upcase

Mongoid.logger.level = log_level
Mongo::Logger.level = log_level

Mongoid.configure do |config|
  uri = if Errbit::Config.mongo_url == 'mongodb://localhost'
          "mongodb://localhost/errbit_#{Rails.env}"
        else
          Errbit::Config.mongo_url
        end

  config.load_configuration(
    clients: {
      default: {
        uri: uri,
        options: { ssl_ca_cert: Rails.root.join('rds-combined-ca-bundle.pem') }
      }
    },
    options: {
      use_activesupport_time_zone: true
    }
  )
end

You can notice that this is exactly the same as current one except for I added: options: { ssl_ca_cert: Rails.root.join('rds-combined-ca-bundle.pem') }

It did work for me after doing this :) Of course you need rds-combined-ca-bundle.pem file to be present at your Rails root folder.

wget https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem

Yes, I've had to create a docker image with the following code:

FROM errbit/errbit:latest
LABEL maintainer="Tarek N. Elsamni <[email protected]>"

WORKDIR /app

RUN wget https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem

COPY ["mongo.rb", "/app/config/"]