How to create a Web API for AWS DocumentDB (using RESTHeart)

Riccardo Corti
May 16 · 6 min read
  1. An EC2 instance running RESTHeart.

Creating the DocumentDB’s cluster

From the AWS Dashboard go to the section dedicated to DocumentDB and click on ‘Create’ a new cluster.



RESTHeart’s configuration

At this point is necessary to create an EC2 instance to run RESTHeart and configure it to call our DocumentDB database.

$ ssh ubutu@<ec2-public-ip>
$ sudo apt install mongodb-clients
$ sudo apt-get install default-jdk
$ wget https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem
$ mongo --ssl --host endpoint –-sslCAFile rds-combined-ca-bundle.pem --username yourMasterUsername --password yourMasterPassword
$ keytool -importcert -file rds-combined-ca-bundle.pem -alias mongoCert -keystore rhTrustStore# asks for password, use "changeit"
$ wget https://github.com/SoftInstigate/restheart/releases/download/3.10.0/restheart-3.10.0.tar.gz$ tar -zxf restheart-3.10.0.tar.gz$ cd restheart-3.10.0/$ ls -l
total 65816
-rw-r--r-- 1 34519 Apr 27 16:01 LICENSE.txt
-rw-r--r-- 1 4995 Apr 27 16:01 README.md
drwxr-xr-x 4 128 May 14 11:41 etc
-rw-r--r-- 1 16825773 Apr 27 16:02 original-restheart.jar
-rw-r--r-- 1 16825773 Apr 27 16:03 restheart.jar
$ export MONGO_URI=’mongodb://restheart:restheart00@docdb-restheart-2019–05–06.cluster-ccexczqns5xm.eu-west-1.docdb.amazonaws.com:27017/ssl=true'
$ java -server -Dfile.encoding=UTF-8 -Djavax.net.ssl.trustStore=rhTrustStore -Djavax.net.ssl.trustStorePassword=changeit -Djavax.security.auth.useSubjectCredsOnly=false -jar restheart.jar
>>> Found environment variable MONGO_URI overriding parameter mongo-uri 
$ curl -i --user admin:changeit -X GET <ec2-public-ip>:8080/
$ http -a admin:changeit GET <ec2-public-ip>:8080/

Conclusions

The compatibility of DocumentDB with MongoDB makes RESTHeart an extremely effective tool for creating a RESTful API on top of the Amazon database. So as we would configure RESTHeart to point to a MongoDB database, we can configure it to access a DocumentDB database.

SoftInstigate Team

Random thoughts about Software Development, Technology, Innovation and Product Strategy.

Riccardo Corti

Written by

SoftInstigate Team

Random thoughts about Software Development, Technology, Innovation and Product Strategy.