DEV Community

Khushi Nandwani
Khushi Nandwani

Posted on

CineDB: Building a Movie Catalog with DocumentDB πŸ“½οΈ

Architecture Diagram

πŸ“˜ Introduction

This project demonstrates how to set up Amazon DocumentDB (with MongoDB compatibility) inside a custom Amazon VPC and securely connect to it from an EC2 instance and covers end-to-end steps starting from network creation, security configuration, cluster provisioning, client setup, and finally performing CRUD (Create, Read, Update, Delete) operations using the MongoDB shell (mongosh).

The goal is to understand how a managed NoSQL database like Amazon DocumentDB is deployed and accessed in a real-world AWS environment.

πŸ—οΈ Architecture Overview

The architecture is based on a private Amazon DocumentDB cluster deployed inside a custom VPC. An EC2 instance placed in a public subnet acts as the client machine to connect securely to the DocumentDB cluster using security groups and TLS encryption.

Key ideas:

  • DocumentDB runs inside private subnets
  • EC2 client accesses it through security group–based rules
  • Communication happens over port 27017 using TLSLS

🧩 Architecture Components

  • Amazon VPC: Custom VPC for isolation and network control
  • Public Subnet: Hosts the EC2 client instance
  • Amazon DocumentDB Cluster: MongoDB-compatible NoSQL database
  • Subnet Group: Defines subnets where DocumentDB can be deployed
  • Security Groups:
    • DocumentDB cluster security group
    • DocumentDB client (EC2) security group
  • Amazon EC2 (Amazon Linux 2): Client machine for database access
  • MongoDB Shell (mongosh): Used to interact with DocumentDB
  • TLS Certificate: Ensures encrypted communication

🎯 Why This Project?

  • To understand how Amazon DocumentDB works in a secure VPC setup
  • To learn networking and security concepts such as VPCs, subnets, and security groups
  • To practice MongoDB-style CRUD operations on a managed AWS service
  • To gain hands-on experience useful for cloud, DevOps, and database roles

✨ Key Features

  • Secure DocumentDB cluster deployment
  • Controlled access using security groups
  • MongoDB-compatible operations using mongosh
  • Full CRUD workflow on a sample movie catalog
  • Proper cleanup of AWS resources to avoid unnecessary costs

πŸ› οΈ Execution Workflow

I. VPC and Subnet Configuration

  • Open the AWS Management Console

AWS Management Console

  • Search for VPC and open the VPC Dashboard

VPC Dashboard

  • Click Create VPC

Creating VPC

  • Set VPC name as documentdb-demo-vpc

VPC Name

  • Keep all other settings as default

Keeping other settings as deafult

  • Click Create VPC

Click Create VPC

  • Once created, click View VPC

Once created, click View VPC

  • Go to Subnets

Go to Subnets

  • Select Public Subnet 1 and click edit subnet settings

Editing subnet settings

  • Enable Auto-assign public IPv4 address

Enable Auto-assign public IPv4 address

  • Save the subnet settings

Save the subnet settings

II. DocumentDB Subnet Group Creation

  • Search for Amazon DocumentDB and open its dashboard

Search for Amazon DocumentDB and open its dashboard

  • From the left menu, click Subnet groups

From the left menu, click Subnet groups

  • Click Create subnet group and enter the following details:
    • Name: documentdb-subnet-group
    • Description: Subnet group for DocumentDB
    • VPC: Select the previously created VPC

Creating subnet group

  • Add all subnets associated with this VPC

Add all subnets associated with this VPC

  • Click Create subnet group

Click Create subnet group

Subnet Group Created

III. Security Group Configuration

A. DocumentDB Cluster Security Group

  • Open EC2 β†’ Security Groups

Open EC2 β†’ Security Groups

  • Click Create security group, in Basic Details configure:
    • Security group name: documentdb-sg
    • Description: Security group for DocumentDB cluster
    • VPC: documentdb-demo-vpc

Configuring Security Group

  • Keep rest of the settings as defailt and click create security group

create security group

SG 1 created

B. DocumentDB Client Security Group

  • Click Create security group again and in Basic Details configure:
    • Security group name: documentdb-client-sg
    • Description: Security group for DocumentDB clients
    • VPC: documentdb-demo-vpc

Creating documentdb-client-sg

  • Add an inbound rule with the following configuration:
    • Type: SSH
    • Port Range: 22
    • Source: Anywhere-IPv4

Creating Inbound Rule

  • Click Create security group

Click Create security group

Security Group created

C. Inbound Rule Configuration

  • Open documentdb-sg and click edit inbound rules

Open documentdb-sg

  • Click Add rule and configure:

    • Type: Custom TCP
    • Port range: 27017
    • Source: documentdb-client-sg
  • Save the rules

Add and configure SG rule

Save rule

IV. Amazon DocumentDB Cluster Creation

  • Open Amazon DocumentDB

Open Amazon DocumentDB

  • Click Create cluster & select instance-based cluster

Click Create cluster & select instance-based cluster

  • In Cluster Configuration, configure:
    • Cluster identifier: movie-catalog-cluster
    • Engine version: 5.0

Cluster Configuration

  • Choose DB instance class: Memory optimized

Choose DB instance class: Memory optimized

  • Keep cluster storage and connectivity settings as default

cluster storage and connectivity settings as default

  • Under Authentication, configure:
    • Username: docdbadmin
    • Enable Self-managed passwords
    • Enter and confirm username and password

Configuring authentication settings

  • Enable Advanced settings

Enable Advanced settings

  • Under Network settings:
    • VPC: documentdb-demo-vpc
    • Subnet group: documentdb-subnet-group
    • Security group: documentdb-sg

Updating Networking Settings

  • Keep remaining settings as default

Keep remaining settings as default

  • Disable Deletion Protection for cluster

Disable Deletion Protection for cluster

  • Click Create cluster

Click Create cluster

  • Wait 10–15 minutes for cluster creation

V. EC2 Client Instance Setup

  • Open Amazon EC2 dashboard and click launch instance

Open Amazon EC2 dashboard and click launch instance

  • Configure:
    • Name: documentdb-client-ec2
    • AMI: Amazon Linux 2
    • Instance type: t2.micro or t3.micro

Configuring a instance

Configuring a instance

  • Create a Key Pair:
    • Name: dynamodb-client
    • Type: RSA
    • Format: .pem

Create a Key Pair

Key Pair

  • In Network settings:
    • VPC: documentdb-demo-vpc
    • Subnet: Choose a public subnet
    • Security group: documentdb-client-sg

Editing Network settings

  • Click Launch instance

Click Launch instance

Instance craeted

VI. Connect to EC2

  • Wait until instance status checks pass and click Connect

Wait until instance status checks pass and click Connect

  • Choose EC2 Instance Connect and Click Connect

Choose EC2 Instance Connect and Click Connect

Instance connected

VII. MongoDB Shell Installation

  • Download MongoDB shell:

wget https://downloads.mongodb.com/compass/mongodb-mongosh-1.10.0.x86_64.rpm

Download MongoDB shell

  • Install mongosh:

sudo yum install -y mongodb-mongosh-1.10.0.x86_64.rpm

Install mongosh

  • Verify installation:

mongosh --version

Verify installation

  • Download DocumentDB TLS certificate:

wget https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem

Download DocumentDB TLS certificate

VIII. Connect to DocumentDB

  • Open Amazon DocumentDB β†’ Clusters

Open Amazon DocumentDB β†’ Clusters

  • Go to Connectivity & Security and copy the mongosh connection string

Connecting Mongosh string

  • Paste it into the EC2 terminal and enter the database password

entering the db password

IX. Database Operations (CRUD)

  • Switch database:

use movieCatalog

Switch database

  • Create collection:

db.createCollection("movies")

Create collection

  • Insert data:

db.movies.insertMany([
{ title: "Inception", genre: "Sci-Fi", releaseYear: 2010, rating: 8.8 },
{ title: "Interstellar", genre: "Sci-Fi", releaseYear: 2014, rating: 8.6 },
{ title: "The Dark Knight", genre: "Action", releaseYear: 2008, rating: 9.0 },
{ title: "Avengers: Endgame", genre: "Superhero", releaseYear: 2019, rating: 8.4 },
{ title: "Parasite", genre: "Thriller", releaseYear: 2019, rating: 8.6 }
])

Insert data

  • Read all movies:

db.movies.find()

Read all movies

Read all movies

  • Find by genre:

db.movies.find({ genre: "Sci-Fi" })

Find by genre

  • Update one movie:

db.movies.updateOne(
{ title: "Interstellar" },
{ $set: { rating: 8.7 } }
)

Update one movie

  • Update multiple movies:

db.movies.updateMany(
{ genre: "Sci-Fi" },
{ $inc: { rating: 0.1 } }
)

Update multiple movies

  • Delete a movie:

db.movies.deleteOne({ title: "Parasite" })

  • Verify deletion:

db.movies.find().pretty()

Verify deletion

  • Compare the total number of documents in the collection after deletion

db.movies.countDocuments()

total number of documents in the collection

πŸ“‚ Full Repository
All source code, configuration steps, and documentation are available here:
https://github.com/Knandwani07/aws-database-architectures/tree/main/documentdb-movie-catalog

X. Cleanup

  • Delete DocumentDB cluster instance and DocumentDB cluster

Delete cluster

  • Delete Subnet Group

Delete Subnet Group

  • Delete EC2 instance

Delete EC2 instance

  • Delete Key Pair

Delete Key Pair

  • Delete Security Groups

Delete Security Groups

  • Delete VPC

Delete VPC

βœ… Conclusion

This project provides a complete, production-style walkthrough of deploying and using Amazon DocumentDB securely within AWS. It covers networking, security, database operations, and cleanup, reflecting real-world cloud practices.

🀝 Let’s Connect

For feedback, collaboration, or cloud discussions:

LinkedIn: https://www.linkedin.com/in/khushi-nandwani/

GitHub: https://github.com/Knandwani07

Top comments (0)