12 Weeks AWS Workshop Challenge
Week Five: Databases
Database Fundamentals
Databases are ideal for storing structured, semi-structured, or unstructured data that will be frequently accessed or referenced by other applications or services.
There are two main categories of databases: relational databases and non-relational databases. Relational Databases are suitable for structured data as they are laid out in a tabular structure which consists of rows and columns, whilst non-relational databases are suitable for semi-structured or unstructured data, that have flexible and complex schemas.
Types of Database Services on AWS
AWS offers various purpose built, fully managed, and highly available databases. Purpose built means that you are spoilt for choice when it comes to choosing the best database for your workload.
1. Relational Databases: Amazon Relational Database (RDS)
Relational databases, are often referred to as traditional databases, because they are the original type of database that existed. Relational databases are best suited for transactional workloads.
Amazon RDS is a fully managed relational databases that is compatible with MySQL, PostgreSQL, MicrosoftSQL Server, Oracle, Amazon Aurora and MariaDB
Amazon Aurora is a proprietary, fully managed relational AWS database that is compatible with MySQL and PostegreSQL.
Amazon RedShift is a fully managed data warehouse solution, for big data and analytics.
2. Key-Value (NoSQL)Databases: Amazon DynamoDB
Key-value databases also known as NoSQL databases are suitable for non-transactional, non-traditional complex datatypes.
Amazon DynamoDB is a scalable NoSQL database.
3. Document Databases: Amazon DocumentDB
Document Databases are suitable for data that is stored as documents.
DocumentDB supports MongoDB workloads. Data in DocumentDB is stored as JSON-like documents.
4. Timestream Databases: Amazon Timestream
Timestream databases are considered schemaless databases. They are suitable for the analysie of time-series data that is often generated by IoT services
Amazon Timestream can store and analyze trillions of events per day.
5. In-memory Databases: Amazon ElasticCache
In memory databases are best suited for applications that require caching & real time access to data.
Amazon ElasticCache offers fully managed implementations of Redis and Memcached.
6. Graph Databases: Amazon Neptune
Graph databases are suitable for applications that work with ‘relationships’ between data, such as social media & recommendation systems.
Amazon Neptune is a fully managed graph database, with millisecond latency.
7. Ledger Databases: Amazon Quantum Ledger Database
Ledger databases provide a centralized, immutable repository of data. Ledger databases are suitable for medical records and financial systems.
Amazon Quantum Ledger Database is highly scalable.
Amazon DynamoDB
Amazon DynamoDB is a NoSQL, key-value, fully managed, serverless, proprietary database offering from AWS.
It is easy to get started with especially when building cloud native applications, as it is highly available and scalable. Amazon DynamoDB can be multi-regional and multi-zonal.
Core Components of Amazon DynamoDB
In Amazon DynamoDB, data is stored in tables with the components in the table being referred to as items. Each item in the table must have a unique partition key.
Tables: a table in DynamoDB, like a table in any other database is a collection of data. Each table can contain zero or more items.
Items: an item in DynamoDB is a group of attributes, like rows and columns in other databases.
Attributes: an attribute in DynamoDB is what an item is composed of. An attribute can be considered atomic or scalar data that doesn’t need to be broken down any further, for example, an ID.
Primary Key: A Primary Key is what uniquely identifies data in a table. In DynamoDB a primary key can either be a partition key, or a combination of a partition key and sort key.
Creating an Amazon DynamoDB Table
Do you have an Amazon DynamoDB Table?
Yes? Well, that’s cool. See you in my next post then.
No? Ok, no big deal, let’s create it quickly.
Prerequisites
To create an Amazon DynamoDB Table you will need:
(1) an AWS account to configure the resources.
Step by Step Guide
How to Create an Amazon DynamoDB Table(via the Management Console)
- Login to the AWS Management Console using your IAM user name.
- We will be using the Oregon (us-west-2) region. So, on the top right navigation bar, make sure Oregon is selected.
- On the top left corner, click on the Services button.
- Select Database on the left side of the drop down menu.
- Select DynamoDB.
- Click the Create table button.
- Table name: myTable.
- Partition key: myPartitionKey (String)
- Sort key — optional: mySortKey (String)
- Table Settings: select the Default settings radio button.
- Click Create table. Wait until the status is Active.
Add Data to the Table
- Click on myTable.
- Click Explore table items.
- Click Create item.
- Add the values. myPartitionKey: The Partition and mySortKey: The Sort.
- Click Create item.
- Repeat the process to add more item for your table: myTable.
- Add the values. myPartitionKey: The Partition Two and mySortKey: The Sort Two.
- Click Create item.
- Repeat the process to add more item for your table: myTable.
- Add the values. myPartitionKey: The Partition Three and mySortKey: The Sort Three.
- Click Create item.
- Repeat the process to add more item for your table: myTable.
- Add the values. myPartitionKey: The Partition and mySortKey: The Sort Four.
- Click Create item.
- Repeat the process to add more item for your table: myTable.
- Add the values. myPartitionKey: The Partition and mySortKey: The Sort Five.
- Click Create item.
- Repeat the process to add more item for your table: myTable
- Your table should have five items.
Query the Table
- Scan or query items: select Query.
- Select a table or index: Table — myTable.
- Select attribute projection: All attributes
- myPartitionKey (PartitionKey): The Partition.
- Equal to: Leave Blank
- Click Run.
- It should return all the items in the myTable where the partition key is The Partition.
Important: Clean Up Resources
- Click on Tables.
- Check myTable and click Delete.
- Check Delete all CloudWatch alarms for myTable.
- Uncheck Create an on-demand backup of myTable before deletion.
- Type confirm.
- Click Delete.
Don’t get a Bill Shock by leaving unnecessary resources running.
End of Step by Step Guide
Conclusion
Congratulations! In this Step by Step Guide, you created an Amazon DynamoDB Table Bucket, created items, and queried it.
…And theoretically, you touched base on the types and use cases of core databases services on AWS. The more you work with AWS Services and with Amazon DynamoDB, you will come to find that you can configure more complex and multi-regional accessible databases.
Blog Post Summary
Theory
Introduction to Databases on AWS.
Practical
Creating an Amazon DynamoDB Table, Creating Items and Querying It.