AWS

4 Mins Read

Connect an Amazon EC2 instance to an Amazon RDS Database

Voiced by Amazon Polly

An ABC Organization host web application on EC2 instance to capture form data in an RDS database. Users of an application will fill & submit the form and then their data will be stored in an RDS database. An ABC Organization need to establish connection between EC2 instance to RDS database to move data from EC2 instance to RDS database.

Maximize Performance and Minimize Throughput Costs with Amazon Dynamo DB

  • Developer friendly
  • Automatic backup and restore
  • Cost effective
Connect Today

Architecture

Prerequisites

Before proceeding, ensure you have:

  • An AWS account with appropriate permissions.
  • A VPC with public and private subnets.
  • An existing or new RDS database (MySQL, PostgreSQL, or another supported engine) in private subnet.
  • An existing or new EC2 instance in public subnet.
  • Both RDS instance and EC2 instance in same VPC.

Step 1: Launch an EC2 Instance (If not created already)

  • Go to the EC2 Console
  • Click on “Launch Instance.”

  • Choose an AMI (Amazon Machine Image)
    • Select Amazon Linux, Ubuntu, or any other Linux distribution.

  • Select an Instance Type
    • Choose an instance type suitable for your workload (e.g., t2.micro for small applications).

  • Add a Key Pair
    • Choose or create an SSH key pair for remote access.

  • Configure Network Settings
    • Ensure the instance is in the same VPC as your RDS database.
    • Enable Auto-assign Public IP if external access is required.

  • Launch the Instance.

 

Step 2: Create an RDS Database (If Not Already Created)

  • Go to the RDS Console. Open the AWS RDS Console.
  • Click on “Create Database.”

 

  • Choose the Database Engine. Select MySQL, PostgreSQL, or another database type.

 

  • Template

 

  • Availability and durability

 

  • Credentials Settings

 

  • Instance configuration

 

  • Storage

 

  • Configure Network Settings
    • Place the database in the same VPC and subnet as the EC2 instance.
    • Ensure Public Access is disabled for security reasons.

 

  • Launch the Database and wait for it to become available.

 

Step 3: Configure Security Groups

Modify EC2 Security Group

  • Go to the EC2 Console → Security Groups.

 

  • Find the security group associated with your EC2 instance.
  • Click Edit outbound rules → Add Rule:
    • Type: MySQL/Aurora (or PostgreSQL, depending on DB engine).
    • Protocol: TCP.
    • Port: 3306 (for MySQL) or 5432 (for PostgreSQL).
    • Destination: The security group of the RDS instance.

 

  • Save the rule.

Modify RDS Security Group

  • Go to the RDS Console → Security Groups.
  • Find the security group for your RDS instance.

 

  • Click Edit inbound rules → Add Rule:
    • Type: MySQL/Aurora (or PostgreSQL).
    • Protocol: TCP.
    • Port: 3306 or 5432.
    • Source: The security group of the EC2 instance.

 

  • Save the rule.

Step 4: Connect EC2 Instance to RDS

  1. SSH into the EC2 Instance. Once your EC2 instance is running, connect via SSH:

 

  1. Install a Database Client

For MySQL:

For PostgreSQL:

 

  1. Connect to RDS Database

For MySQL:

Enter password of database

 

For PostgreSQL:

 

  1. If the connection is successful, you will see a list of available databases.

Save Time and Money with Automated and Customizable Data Insights

  • Highly Scalable
  • Cost- effective
  • Smart Visualizations
Get started with Amazon QuickSight Today

About CloudThat

CloudThat is an award-winning company and the first in India to offer cloud training and consulting services worldwide. As a Microsoft Solutions Partner, AWS Advanced Tier Training Partner, and Google Cloud Platform Partner, CloudThat has empowered over 850,000 professionals through 600+ cloud certifications winning global recognition for its training excellence including 20 MCT Trainers in Microsoft’s Global Top 100 and an impressive 12 awards in the last 8 years. CloudThat specializes in Cloud Migration, Data Platforms, DevOps, IoT, and cutting-edge technologies like Gen AI & AI/ML. It has delivered over 500 consulting projects for 250+ organizations in 30+ countries as it continues to empower professionals and enterprises to thrive in the digital-first world.

Share

Comments

    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!