Disaster Recovery with Global Clusters

If cluster in one AWS region becomes unavailable, you can promote another cluster in the global cluster to a standalone cluster that can perform reads and writes.

The following procedure outlines how to promote one of the secondary clusters in a global cluster.

To promote a secondary cluster

  1. Stop issuing DML statements and other write operations to the primary DocumentDB cluster.
  2. Identify a DocumentDB cluster from a secondary AWS Region to use as a new primary cluster. If you have two (or more) secondary AWS Regions in your DocumentDB global cluster, choose the secondary cluster that has low latency for your applications. Secondary Cluster.
  3. Remove the selected secondary DB cluster from the DocumentDB global cluster.

    Removing a secondary cluster from an DocumentDB global cluster immediately stops the replication to this secondary and promotes it to standalone DocumentDB cluster with read/write capabilities. Any other secondary DocumentDB cluster(s) associated with the primary cluster is still available and can accept requests from your application. Since you are recreating the DocumentDB global cluster, to avoid split-brain and other issues, it is recommended to remove the other secondary clusters before creating a new DocumentDB global cluster.

    Remove From Global

Remove And Promote For detailed steps for detaching, see Removing a cluster from an Amazon DocumentDB global cluster.

  1. Reconfigure your application to send write operations to this standalone DocumentDB cluster using its new endpoint. If you accepted the provided names when you created the DocumentDB global cluster, you can change the endpoint by removing the -ro from the cluster’s endpoint string in your application.

    For example, the secondary cluster’s endpoint getting-started-with-documentdb-secondary.cluster-ro-aaaaaabbbbbb.us-east-1.docdb.amazonaws.com becomes getting-started-with-documentdb-secondary.cluster-aaaaaabbbbbb.us-east-1.docdb.amazonaws.com when that cluster is removed from the DocumentDB global cluster.

    Note: Execute below commands in the secondary region Cloud9 IDE.

    Insert documents in newly promoted standalone cluster
    export clusterendpoint=`aws docdb describe-db-clusters --query "DBClusters[*].Endpoint" --output text`
    
    mongo --quiet --ssl --host $clusterendpoint:27017 --sslCAFile rds-combined-ca-bundle.pem --username $docdbUser --password $docdbPass
    
    var data=[];
    for (var i=2000000; i<2000004; i++){
        var doc = {
            "_id": NumberLong(i),
            "createDate": new Date()
        };
        data.push(doc);
    }
    
    db.getSiblingDB("sampledb").test.insertMany(data);
    
    

    The output for this query retuns the _id of the documents inserted to standalone cluster.

    {
            "acknowledged" : true,
            "insertedIds" : [
                    NumberLong(2000000),
                    NumberLong(2000001),
                    NumberLong(2000002),
                    NumberLong(2000003)
            ]
    }
    
    Reading documents from standalone cluster

    Use the below query to read data inserted to Amazon DocumentDB. The find API takes a filter criteria and returns the document matching the criteria. You can optionally use pretty() to pretty print the output.

    db.getSiblingDB("sampledb").test.find({"_id": NumberLong(2000000)}).pretty();
    

    The matched document is returned as the output of the above query.

    {
        "_id" : NumberLong(2000000),
        "createDate" : ISODate("2021-06-14T20:19:56.857Z")
    }
    

    This DocumentDB cluster becomes the primary cluster of a new DocumentDB global cluster when you start adding regions to it, in the next step.

    You can add regions to this standalone cluster to convert it to a global cluster. To go back to the original cluster, i.e when the old primary region is up , perform the steps outlined above in reverse order.