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:
- Model relationships in data.
- Query data quickly and flexibly.
- Support multi-user reads/writes (multiple people using the library at the same time).
- Enable transactional consistency (ACID compliance - updates in near real-time).
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)
π‘ 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.
RDS: Creating a Database π’
- Choose Engine
- Configure DB instance settings (storage, memory, availability, VPC/network settings, security groups)
- Launch DB Instance (AWS handles provisioning)
- 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:
- GUI tools (e.g., pgAdmin, DBeaver)
- CLI tools (e.g., psql)
- 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
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.)
Summary: RDS vs. DynamoDB π’
π― 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)