Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • DevOps Lifecycle
  • DevOps Roadmap
  • Docker Tutorial
  • Kubernetes Tutorials
  • Amazon Web Services [AWS] Tutorial
  • AZURE Tutorials
  • GCP Tutorials
  • Docker Cheat sheet
  • Kubernetes cheat sheet
  • AWS interview questions
  • Docker Interview Questions
  • Ansible Interview Questions
  • Jenkins Interview Questions
Open In App
Next Article:
AWS CLI for Relational Database Service
Next article icon

AWS CLI for Relational Database Service

Last Updated : 02 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

As we know, Amazon Web Services (AWS) provides more than 200 IT and infrastructure management services. The question arises: can we only access and manage those services through the AWS Management Console? The answer is no. We can access and interact with those services through the AWS Management Console, which is a web-based interface, the AWS Command Line Interface (AWS CLI), which is used through a terminal; and the AWS SDK (AWS Software Development Kit), which is basically used in applications. Here we are deep diving into the AWS CLI and exploring how it interacts with the AWS RDS. Here, RDS supports various popular database engines such as MySQL, PostgreSQL, MariaDB, Oracle, and Microsoft SQL Server. A basic understanding of best practices that enhance your skill to use AWS CLI with RDS to automate database tasks, manage resources, and integrate RDS with other resources in an efficient manner.

Primary Terminologies

  • AWS CLI: The AWS Command Line Interface (CLI) is a powerful and open-source command-line Interface that is basically used to interact with various AWS services. through this tool you can download, configure and manage your AWS services and automate them though writing scripts.
  • RDS (Relational Database Service): Amazon Relational Database Service (RDS) is a fully managed AWS Relational Database Service that is easy to set up, operate, and automatically scale a relational database in the cloud. Here, you only focus on your application optimization; other parts will be handled automatically, such as installing and patching software and databases, high availability and scaling, server maintenance, database backups, etc.
  • DB Instance: A DB instance is an isolated database environment in the cloud. Each instance runs a single database engine and can use standard database client applications.
  • DB Snapshot: A DB snapshot is a backup of your DB instance that is stored in Amazon S3, and in another way, we can say that it is a static view of our SQL server database that is read-only.
  • DB Parameter Group: A DB parameter group acts as a container for engine configuration that controls how your database operates.
  • Endpoint: An endpoint is a URL that includes the network address (DNS address) and port number of your database instance.

Step-by-Step Guide for Relational Database Service using AWS CLI

Before starting, Make sure that you have an have AWS Account with needed permission to manage RDS resources and AWS CLI installed and configured on your system.

Step 1: Configuring AWS CLI

  • Install AWS CLI: Follow the instructions from the AWS CLI documentation for installing AWS CLI as per your operating system.
  • Configure AWS CLI: After Installing AWS CLI you configure your AWS CLI through following command.
aws configure

After that you enter some necessary information such as,

  • Your AWS access key,
  • Secret key,
  • Region, and output format.
Configuring AWS CLI

IAM Permission

If you want to manage the RDS resources using AWS CLI, first check that the IAM user or role has the following permissions:

  • rds:CreateDBInstance
  • rds:ModifyDBInstance
  • rds:DeleteDBInstance
  • rds:CreateDBSnapshot
  • rds:RestoreDBInstanceFromDBSnapshot

Creating and attaching custom IAM Policy

aws iam create-policy \
--policy-name RDSManagementPolicy \
--policy-document '{
"Version": "2023-05-25",
"Statement": [
{
"Effect": "Allow",
"Action": [
"rds:CreateDBInstance",
"rds:ModifyDBInstance",
"rds:DeleteDBInstance",
"rds:CreateDBSnapshot",
"rds:RestoreDBInstanceFromDBSnapshot",
"rds:DescribeDBInstances",
"rds:RebootDBInstance"
],
"Resource": "*"
}
]
}'

Attach the policy to your IAM user or role:

aws iam attach-user-policy     
--policy-arn arn:aws:iam::aws:policy/RDSManagementPolicy
--user-name your-iam-username

Step 2: Creating a DB Instance

To create a new DB instance, use the following command:

aws rds create-db-instance     
--db-instance-identifier mydbinstance
--db-instance-class db.t2.micro
--engine mysql
--allocated-storage 20
--master-username admin
--master-user-password mypassword

Above command will create a MySQL DB instance named 'mydbinstance' with the specified instance class, storage, and credentials. You can check the result in the AWS Command Line interface by using the command given above.

create db

You can check the result in the AWS Management Console by using the command given above.

db

Step 3: Modifying a DB Instance

To modify an existing DB instance, such as changing the allocated storage, use the following command:

aws rds modify-db-instance     
--db-instance-identifier mydbinstance
--allocated-storage 30
--apply-immediately

This command increases the storage size of 'mydbinstance' to 30 GiB. You can check the result in the AWS Command Line interface by using the command given above.

modify

You can check the result in the AWS Management Console by using the command given above.

console

Step 4: Creating a DB Snapshot

To create a snapshot of your DB instance, use the following command:

aws rds create-db-snapshot 
--db-instance-identifier mydbinstance
--db-snapshot-identifier mydbsnapshot

This command creates a snapshot named 'mydbsnapshot'.

Note: When you write this command, that time snapshot will be created automatically, but in the terminal, there is no output data until you restore a DB instance from a snapshot.

You can check the result in the AWS Management Console by using the command given above.

snapshot

Step 5: Restoring a DB Instance from a Snapshot

Here we are restoring DB instance from a snapshot, use the following command:

aws rds restore-db-instance-from-db-snapshot 
--db-instance-identifier mynewdbinstance
--db-snapshot-identifier mydbsnapshot

Above command through we can create a new DB instance 'mynewdbinstance' from existing 'mydbsnapshot' snapshot. You can check the result in the AWS Command Line interface by using the command given above.

new DB instance

You can check the result in the AWS Management Console by using the command given above.

AWS Management Console

Step 6: Finally Deleting a DB Instance

To delete a DB instance, use the following command:

aws rds delete-db-instance 
--db-instance-identifier mydbinstance
--skip-final-snapshot

This command deletes 'mydbinstance' without creating a final snapshot.

To delete a DB instance that was created through a snapshot, use the following command:

aws rds delete-db-instance     
--db-instance-identifier mynewdbinstance
--skip-final-snapshot

This command deletes 'mynewdbinstance' without creating a final snapshot. You can check the result in the AWS Command Line interface by using the command given above.

Picture 5.1: That shows when you delete 'mydbinstance' instance.

delete
Picture 5.1

Picture 5.2: That shows when you delete 'mynewdbinstance' instance.

shows when you delete
Picture 5.2

You can check the result in the AWS Management Console by using the command given above.

Picture 5.1: That shows when you delete 'mydbinstance' instance.

console
Picture 5.1

Picture 5.2: That shows when you delete 'mynewdbinstance' instance.

deleting
Picture 5.2

Picture 5.3: That shows finally all the instances are deleted, Nothing any instance here.

deleted
Picture 5.3

Conclusion

The AWS CLI is a powerful tool for managing AWS services, including Amazon RDS, that enables high-performance deployment and scripting of database services. With the necessary IAM permissions, you can create, modify, copy, restore, and delete RDS instances with simple commands, saving time and reducing human error. This approach optimizes resource management, ensures scalability and cost effectiveness in your cloud infrastructure deployment.


Next Article
AWS CLI for Relational Database Service

R

romilmovaliya
Improve
Article Tags :
  • Amazon Web Services
  • DevOps
  • AWS

Similar Reads

    AWS Database Migration Service (DMS)
    The AWS Database Migration Service (DMS) helps you quickly and safely transfer your databases. It also lets you build, analyze, transform, and relocate databases and analytics platforms all in one place, saving you time, resources, and money. In that process, application downtime, based on the sourc
    9 min read
    AWS CLI for Service Health Monitoring
    AWS has numerous services, and for your application to run smoothly, it is necessary to keep a check on the status of the services. AWS CLI provides a unified set of commands that enable you to programmatically monitor the health and status of AWS services and resources. Monitoring service health th
    6 min read
    KMS Commands: AWS CLI for Key Management Service
    AWS Key Management Service is a fully managed service that enables the user to create and control the encryption keys that encrypt their data. AWS KMS is very instrumental in securing sensitive information for data integrity in a secure cloud environment. AWS KMS integrates well with different AWS s
    5 min read
    AWS RDS - Launching RDS Database Instance for Free
    In this article we will look into how you can launch an Amazon RDS database instance that's covered by the AWS free tier. To do so follow the below steps: Amazon RDS free tier is available to you only in the first 12 months of your AWS account creation. Each calendar month, the free tier allows you
    3 min read
    AWS CLI for Continuous Integration
    Quick and efficient delivery of quality code is at the core of software development in the fast-paced arena. Practically, Continuous Integration (CI) has emerged as a lynchpin practice to this aim, where developers regularly integrate changes in the code into the shared repository. These integration
    6 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences