DEV Community

Cover image for Building Your DB Server and Interacting With Your DB Using an App on AWS
Emmanuel Oghre
Emmanuel Oghre

Posted on

Building Your DB Server and Interacting With Your DB Using an App on AWS

Welcome to another AWS lab walkthrough! In this session, we'll guide you through setting up a relational database server on Amazon RDS and interacting with it through a web application. By the end of this lab, you'll have a fully functional setup where your database is not only deployed but also actively serving a web application.

Overview
Lab Title: Build Your DB Server and Interact With Your DB Using an App
AWS Version: 4.6.6 (TESS2)
Duration: Approximately 30 minutes

Scenario

Image description

At the end of the lab the infrastructure will look like this.

Image description

Objectives
After completing this lab, you will be able to:

Launch an Amazon RDS DB instance with high availability.
Configure the DB instance to permit connections from your web server.
Open a web application and interact with your database.
Scenario
Imagine you start with a basic infrastructure setup, and through this lab, you'll evolve it into a more robust architecture capable of hosting a scalable and resilient database solution.

Step-by-Step Guide
Task 1: Create a Security Group for the RDS DB Instance
Navigate to VPC: In the AWS Management Console, go to Services > VPC.
Create Security Group: Click on Security Groups in the left pane and then Create security group.
Security group name: DB Security Group
Description: Permit access from Web Security Group
VPC: Lab VPC
Configure Inbound Rules: Add a rule to permit inbound database requests.
Type: MySQL/Aurora (3306)
Source: Type "sg" and select Web Security Group.
Create Security Group: Finish by clicking Create security group.
Task 2: Create a DB Subnet Group
Navigate to RDS: In the AWS Management Console, go to Services > RDS.
Create DB Subnet Group:
Click on Subnet groups in the left pane and then Create DB Subnet Group.
Name: DB-Subnet-Group
Description: DB Subnet Group
VPC: Lab VPC
Add Subnets:
Select subnets from at least two Availability Zones (e.g., us-east-1a and us-east-1b).
Choose subnets associated with CIDR ranges like 10.0.1.0/24 and 10.0.3.0/24.
Create DB Subnet Group: Click Create.
Task 3: Create an Amazon RDS DB Instance
Launch RDS Instance:
In the RDS console, click Databases in the left pane and then Create database.
Select MySQL under Engine Options.
Choose Dev/Test under Templates.
Select Multi-AZ DB instance for Availability and durability.
Configure Settings:
DB instance identifier: lab-db
Master username: main
Master password: lab-password
DB instance class: db.t3.micro
Allocated storage: 20 GB
Virtual Private Cloud (VPC): Lab VPC
Security group: Select DB Security Group.
Additional Configurations:
Initial database name: lab
Uncheck Enable automatic backups and Enable encryption for lab purposes.
Create Database: Click Create database.
Task 4: Interact with Your Database
Access Web Server IP: Retrieve the IP address of your web server from the AWS console.
Open Web Application: Paste the WebServer IP address into a browser tab and press Enter.
Navigate to the RDS link displayed on the page.
Configure Database Connection:
Enter the Endpoint (copied from RDS console earlier).
Database: lab
Username: main
Password: lab-password
Click Submit.
Test Application: The web application should display an Address Book.
Add, edit, and remove contacts to verify database functionality.

Note!!! You can configure the password, admin and database name as you see fit

Conclusion
Congratulations! You have successfully completed the lab. You've learned how to deploy a high-availability RDS database instance on AWS, configure security settings, and integrate it with a web application. This setup ensures your database is not only robust but also scalable and fault-tolerant, suitable for various production workloads.

For more AWS tips and guides, stay tuned to our blog or explore further in the AWS documentation. Happy cloud computing!

With this guide, you're now equipped to handle AWS RDS deployments and database interactions like a pro. Let me know if you have any questions or need further assistance!

Top comments (0)