How to Configure and Use Databases on AWS
AWS provides a wide range of database services to manage, store, and analyze your data. Two of the most popular databases you can use within the AWS free tier are Amazon DynamoDB and Amazon Aurora. This guide will walk you through configuring and using both databases, explaining everything in simple terms, and showing how you can use them within the free tier limits.
1. Sign In to AWS
- Step 1: Open the AWS website at https://aws.amazon.com.
- Step 2: Log in with your AWS credentials. If you don’t have an account, you can create a free one.
- Step 3: After logging in, you will be directed to the AWS Management Console, where you can access all AWS services.
2. Navigate to the Database Services
- Step 1: In the AWS Management Console, search for DynamoDB or Aurora in the search bar at the top.
- Step 2: Click on DynamoDB or RDS (for Aurora) under the Database section to start configuring your database.
Configuring and Using Amazon DynamoDB
What is DynamoDB?
DynamoDB is a fully managed NoSQL database service provided by AWS. It’s designed for applications that need consistent, low-latency access to data, such as mobile apps, web apps, and gaming applications. DynamoDB stores data in key-value pairs and is highly scalable, which means you can store large amounts of data and scale it easily.
DynamoDB is particularly useful for applications that require fast and predictable performance at any scale, and it works seamlessly with other AWS services.
Step 1: Create a DynamoDB Table
- Go to the DynamoDB Console:
- In the AWS Management Console, search for DynamoDB and select it from the list.
- Create a New Table:
- Click on “Create table” in the DynamoDB dashboard.
- Configure Table Details:
- Table Name: Give your table a name (e.g.,
MyTable
). - Primary Key: Choose a primary key for your table. The primary key can either be:
- Partition Key (simple key), or
- Partition Key + Sort Key (composite key).
- For example, if you are storing user data, you might use
UserID
as the Partition Key andTimestamp
as the Sort Key.
- Table Name: Give your table a name (e.g.,
- Set Provisioned or On-demand Capacity Mode:
- On-demand: Best for beginners, as it automatically scales based on usage. You don’t need to worry about setting the read and write capacity.
- Provisioned: Allows you to set the read and write capacity manually, which can be useful for predictable workloads.
- Create Table:
- After entering the details, click “Create”. DynamoDB will create your table within seconds.
Step 2: Add Data to DynamoDB
You can add data manually or through your application using the AWS SDKs.
- Manual Data Entry:
- Go to the “Items” tab of your table.
- Click “Create item” to add a new record.
- Add attributes to the item. For example:
- UserID:
22610032
- Name:
Aditya Godse
- Email:
adimail2404@gmail.com
- UserID:
- Using SDK:
- To add items using the AWS SDK, you can write code in Python, JavaScript, or other supported languages. Here’s an example using Python and
boto3
:import boto3 dynamodb = boto3.resource('dynamodb') table = dynamodb.Table('MyTable') table.put_item( Item={ 'UserID': '22610032', 'Name': 'Aditya Godse', 'Email': 'adimail2404@gmail.com' } )
- To add items using the AWS SDK, you can write code in Python, JavaScript, or other supported languages. Here’s an example using Python and
Step 3: Retrieve Data from DynamoDB
- Get Item:
- In the “Items” tab, click on the “Get item” button.
- Enter the primary key (e.g.,
UserID = 22610032
) to retrieve the record.
- Using SDK:
- Here’s how you can fetch a record using Python:
response = table.get_item( Key={ 'UserID': '22610032' } ) print(response['Item'])
- Here’s how you can fetch a record using Python:
Step 4: Delete Data from DynamoDB
- Delete Item Manually:
- In the “Items” tab, select the item you want to delete and click “Delete”.
- Using SDK:
- Here’s how you can delete an item using Python:
table.delete_item( Key={ 'UserID': '22610032' } )
- Here’s how you can delete an item using Python:
Free Tier Usage for DynamoDB
- Free Tier Limits: DynamoDB offers 25 GB of storage and up to 25 read and 25 write capacity units per month for free. This is sufficient for small-scale applications, and you can use it without worrying about extra costs if your usage is low.
Configuring and Using Amazon Aurora (with MySQL/PostgreSQL)
What is Amazon Aurora?
Amazon Aurora is a fully managed relational database service compatible with MySQL and PostgreSQL. It offers the performance and availability of high-end commercial databases, but at a lower cost. Aurora is highly scalable, reliable, and designed for demanding applications that need to process large amounts of transactional data.
Step 1: Create an Aurora DB Cluster
- Go to the RDS Console:
- In the AWS Management Console, search for RDS (Relational Database Service) and select it from the list.
- Create a Database:
- Click “Create database” in the RDS dashboard.
- Select Amazon Aurora as the database engine.
- Choose Database Edition:
- MySQL-Compatible Edition or PostgreSQL-Compatible Edition. Choose the one based on your application needs.
- Configure DB Cluster:
- DB Cluster Identifier: Give your Aurora DB cluster a name (e.g.,
my-aurora-cluster
). - Master Username: Choose the username for your database administrator account.
- Master Password: Set a password for the administrator account.
- Instance Type: Choose the db.t3.small instance for the free trial, which offers 20 GB of storage and 750 hours of usage per month.
- DB Cluster Identifier: Give your Aurora DB cluster a name (e.g.,
- Free Tier Usage:
- Aurora comes with 750 hours of free usage for db.t3.small instances and 20 GB of storage per month for the first 12 months under the AWS free tier.
- Launch DB Cluster:
- Click “Create database” to launch your Aurora DB cluster.
Step 2: Connect to Aurora Database
- Get Database Endpoint:
- After the DB cluster is created, go to the “Connectivity & security” tab.
- Copy the endpoint (hostname) of the Aurora database.
- Connect to the Database:
- Use MySQL Workbench (for MySQL) or any other database client to connect to your Aurora instance. Here’s an example of how to connect using MySQL command line:
mysql -h <endpoint> -u <master_user> -p
- Use MySQL Workbench (for MySQL) or any other database client to connect to your Aurora instance. Here’s an example of how to connect using MySQL command line:
Step 3: Use Aurora Database
- Create a Database:
- Once connected, create a database:
CREATE DATABASE mydatabase;
- Once connected, create a database:
- Create Tables:
- Create a table to store data:
CREATE TABLE users ( UserID INT PRIMARY KEY, Name VARCHAR(100), Email VARCHAR(100) );
- Create a table to store data:
- Insert Data:
- Insert some data into the table:
INSERT INTO users (UserID, Name, Email) VALUES (1, 'Aditya Godse', 'adimail2404@gmail.com');
- Insert some data into the table:
- Query Data:
- Retrieve data from the table:
SELECT * FROM users;
- Retrieve data from the table:
Step 4: Delete Data from Aurora
- Delete Table:
- Drop the table to remove all its data:
DROP TABLE users;
- Drop the table to remove all its data:
- Delete DB Cluster:
- If you no longer need the database, you can delete the entire DB cluster from the RDS console to stop any ongoing charges.
Free Tier Usage for Aurora
- Free Tier Limits: Amazon Aurora offers 750 hours per month of db.t3.small instances for MySQL or PostgreSQL, along with 20 GB of storage, for the first 12 months under the free tier.
Conclusion
Both Amazon DynamoDB and Amazon Aurora offer powerful, fully managed database solutions that are easy to configure and use within the AWS free tier. DynamoDB is perfect for NoSQL workloads, while Aurora is ideal for relational database applications requiring high availability and performance. By following this guide, you can start using these databases effectively without exceeding the free tier limits.