DEV Community

Ayo
Ayo

Posted on

Beginner's AWS Guide: Databases (Part 5)

Objective:

This section dives into databases and builds upon the storage concepts covered in the Beginner's AWS Guide: Storage Services (Part 3). Here, we explore databases and look into RDS (relational databases) and DynamoDB (NoSQL) as popular service options available in AWS.


Databases vs Storage Services

A database is a system that stores, organises, and queries structured or semi-structured data at scale.

Simple Library Analogy for Databases

  • The library shelves = tables
  • Academic books = structured data
  • Magazines = semi-structured data
  • Search system = query engine

We don't just store data in a library β€” we organise and query it efficiently. This has its benefits, including being able to:

  1. Model relationships in data.
  2. Query data quickly and flexibly.
  3. Support multi-user reads/writes (multiple people using the library at the same time).
  4. Enable transactional consistency (ACID compliance - updates in near real-time).

Image highlighting the different feature sets between databases and simple storage options

The link below discusses Relational Databases vs. NoSQL Document Databases in greater depth. I highly recommend having a read to understand the differences between the two: https://lennilobel.wordpress.com/2015/06/01/relational-databases-vs-nosql-document-databases/


RDS: Relational Database Service 🏒

RDS is a managed AWS service for creating and managing SQL-based relational databases. For example, we can choose from popular database engines such as:

  • PostgreSQL
  • MySQL
  • Microsoft SQL Server
  • Oracle
  • MariaDB
  • Aurora (AWS's own SQL database engine)

Image highlighting an example of an efficient SQL query

Table describing how RDS works

πŸ’‘ We configure RDS, even though it uses EC2 instances behind the scenes to run our databases.

RDS handles the entire EC2 layer for us β€” including provisioning the server, managing the operating system, handling scaling, and monitoring β€” so we never need to access or manage the EC2 instance directly.

We simply choose our engine options, instance type, storage, and other settings β€” and RDS takes care of the rest.

Image showing table of benefits when using RDS


RDS: Creating a Database 🏒

  1. Choose Engine
  2. Configure DB instance settings (storage, memory, availability, VPC/network settings, security groups)
  3. Launch DB Instance (AWS handles provisioning)
  4. Connect & Use

DB connection info to note via the AWS console:

  • Our set DB name
  • Master Username/Password - DB login details
  • DNS Connection Endpoint (e.g. mydb.abc123.rds.amazonaws.com)
  • Port (e.g., default: 5432 for PostgreSQL)

πŸ’‘ The DNS endpoint is how AWS gives us a stable and reliable way to connect to our database β€” even if the underlying IP changes. Meanwhile, the port is required as it tells the OS which application (PostgreSQL, MySQL, etc.) is handling the request!

Connect via:

  1. GUI tools (e.g., pgAdmin, DBeaver)
  2. CLI tools (e.g., psql)
  3. Application code (e.g., Python, Node.js + drivers)

Once connected, we can finally create our database structure, i.e. create tables, insert data, and run queries.


DynamoDB: NoSQL Database Service 🏒

DynamoDB is AWS’s serverless NoSQL database designed for speed, scalability, and simplicity. We delve into serverless computing in "Serverless and Modern Computing (Part 7)", but essentially it means we do not need to manage any server infrastructure (AWS does!).

DynamoDB stores data in tables using:

  • Key-value pairs
  • Documents (typically in a JSON-like format)

Each row in a table is called an 'item', and each item can be up to 400KB in size.

Partition Key: Groups related items under a unique identifier
Sort Key (optional): Orders items within the group
Attributes: The actual data stored within the item

Image highlighting DynamoDB structure in AWS - it notes primary keys as the key, and attributes as the value

EXAMPLE: ONLINE-STORE

  • When a customer makes a purchase, they are assigned a partition key, e.g. Customer-ABC, to uniquely identify them.
  • By adding a sort key (e.g. OrderDate or OrderID), we can store multiple orders under that same customer and organise them chronologically or by another order-specific attribute.
  • This structure lets us group and query all of a customer's purchases easily, enabling features like tracking spending patterns, generating order histories, or sending targeted promotional offers.

DynamoDB: Creating a Database 🏒

(1) Create a Table

  • Set the table name (e.g. Users)
  • Define a partition key (e.g. UserID)
  • Add an optional sort key (e.g. Timestamp)

(2) Configure Table Settings

  • Read/Write Capacity (how much traffic our table can handle)
  • On-Demand vs Provisioned mode (auto scaling our table or setting planned capacity)
  • Optionally enable Global Tables, which quickly replicates our table across multiple AWS regions

(3) Add Data via:

  • AWS Console (manually)
  • AWS CLI (put-item)
  • SDKs (Python boto3, JavaScript, etc.)

Image showcasing the different options to add data to a DynamoDB table


Summary: RDS vs. DynamoDB 🏒

Table summarising the key differences between RDS and DynamoDB

Table explaining the difference between managed instances in RDS and serverless computing with DynamoDB

Image showing comparative use value of DynamoDB vs RDS


🎯 TL;DR

  • RDS provides all-in-one managed relational database engines (MySQL, PostgreSQL)
  • DynamoDB is a fast NoSQL database perfect for quick retrieval of lightweight data
  • AWS handles scaling and maintenance in both, so that we can prioritise focus elsewhere.

✨ This is part of a mini-series where I delve into everything cloud-related. Check out my other posts for further learning! ✨

Top comments (0)