Greetings
I was once tasked with setting up an earlier version of a database system for a demo. It took me a whole day to complete that task due to versioning issues in the required libraries. It was nothing but just pain. I lost valuable time as a developer that I can use for something more useful than struggling with setting up a database system.
This is why cloud-based solutions are much better. AWS RDS provides us with many benefits over using traditional on-premises systems.
I was once tasked with setting up an earlier version of a database system for a demo. It took me a whole day to complete that task due to versioning issues in the required libraries. It was nothing but just pain. I lost valuable time as a developer that I can use for something more useful than struggling with setting up a database system.
This is why cloud-based solutions are much better. AWS RDS provides us with many benefits over using traditional on-premises systems.
- OS upgrades and patching
- Automatic backups
- Replication
- High availability
- Security
- Multiple database options
- Hardware and networking
AWS RDS
Amazon Relational Database Service (Amazon RDS) is a collection of managed services that makes it simple to set up, operate, and scale databases in the cloud.
We can choose from seven popular engines.
MySQL, MariaDB, PostgreSQL, Oracle, SQL Server, Aurora MySQL, and Aurora PostgreSQL.
We can even deploy on-premises with RDS on AWS Outposts.
MySQL, MariaDB, PostgreSQL, Oracle, SQL Server, Aurora MySQL, and Aurora PostgreSQL.
We can even deploy on-premises with RDS on AWS Outposts.
In addition, we can leverage memory optimizations, storage selections, CPU
utilisations, and extra security which are nearly impossible in on-premises.
Terminology summary
DB instances
A DB instance is an isolated database environment in the AWS Cloud. The basic building block of Amazon RDS is the DB instance.DB engines
A DB engine is the specific relational database software that runs on your DB instance.DB instance classes
A DB instance class determines the computation and memory capacity of a DB instance. A DB instance class consists of both the DB instance type and the size. Each instance type offers different computing, memory, and storage capabilities.DB instance storage
Amazon EBS provides durable, block-level storage volumes that you can attach to a running instance. DB instance storage comes in the following types:- General Purpose (SSD)
- Provisioned IOPS (PIOPS)
- Magnetic
Create an AWS RDS instance using CloudFormation
Let's create a publicly accessible database instance for this example.
However, note that this is not the best practice. We should always put our
database in a secure network.
AWSTemplateFormatVersion: '2010-09-09' Resources: DBInstance: Type: AWS::RDS::DBInstance Properties: Engine: mysql DBInstanceIdentifier: MyDBInstance MasterUsername: admin MasterUserPassword: Password123 DBInstanceClass: db.t2.micro StorageType: gp2 AllocatedStorage: 20 PubliclyAccessible: true VPCSecurityGroups: - !GetAtt DBSecurityGroup.GroupId DBSecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: Enable public access to the RDS DB instance on port 3306 SecurityGroupIngress: - CidrIp: 0.0.0.0/0 IpProtocol: tcp FromPort: 3306 ToPort: 3306 Outputs: DBEndpoint: Value: !GetAtt DBInstance.Endpoint.Address
You either upload the template through the console or use AWS CLI. I'm using the CLI here.
aws cloudformation deploy --template-file ./aws-rds.yml --stack-name my-rds-stack --region us-east-1
This will take a few minutes to create the resources.
Connect to the database
Once the RDS instance is initiated we can connect to it using any client. Let's use MySql CLI for this demonstration.
mysql -u admin -pPassword123 -h mydbinstance.c3ubptnkp6pt.us-east-1.rds.amazonaws.com -P 3306
When the connection is established, we can create our database and use it.
mysql> create database mydb;
mysql> use mydb;
Let's create a countries table.
mysql> create table countries (name varchar(255));
mysql> insert into countries(name) values('Sri Lanka');
mysql> select * from countries;
Delete the stack
That is the end of this demo. Don't forget to delete your RDS instance.
aws cloudformation delete-stack --stack-name my-rds-stack --region us-east-1
That's it guys! enjoy your cloud journey ☺
Comments
Post a Comment