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 a leading provider of Cloud Training and Consulting services with a global presence in India, the USA, Asia, Europe, and Africa. Specializing in AWS, Microsoft Azure, GCP, VMware, Databricks, and more, the company serves mid-market and enterprise clients, offering comprehensive expertise in Cloud Migration, Data Platforms, DevOps, IoT, AI/ML, and more.

CloudThat is the first Indian Company to win the prestigious Microsoft Partner 2024 Award and is recognized as a top-tier partner with AWS and Microsoft, including the prestigious ‘Think Big’ partner award from AWS and the Microsoft Superstars FY 2023 award in Asia & India. Having trained 650k+ professionals in 500+ cloud certifications and completed 300+ consulting projects globally, CloudThat is an official AWS Advanced Consulting Partner, Microsoft Gold Partner, AWS Training PartnerAWS Migration PartnerAWS Data and Analytics PartnerAWS DevOps Competency PartnerAWS GenAI Competency PartnerAmazon QuickSight Service Delivery PartnerAmazon EKS Service Delivery Partner AWS Microsoft Workload PartnersAmazon EC2 Service Delivery PartnerAmazon ECS Service Delivery PartnerAWS Glue Service Delivery PartnerAmazon Redshift Service Delivery PartnerAWS Control Tower Service Delivery PartnerAWS WAF Service Delivery PartnerAmazon CloudFrontAmazon OpenSearchAWS DMS and many more.

To get started, go through our Consultancy page and Managed Services PackageCloudThat’s offerings.

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!