Cloud Databases - Aurora Database with EC2
Create an Amazon Aurora DB and connect it with Amazon EC2!
DIFFICULTY
: Easy TIME
: 1 Hour COST
: 0$
WHAT YOU'LL NEED
: An AWS account - Create one here!
AWS SERVICES
:
Amazon Aurora
Relational Databases
EC2
Overview
we're creating an Amazon Aurora database to store and display data for our very own web application!
We won't create the web app itself just yet - that's for the next project in this series. But, this project is going to teach you how to connect your Aurora database to the web server (EC2 instance) hosting that web app! Yup, get ready to connect a database service to EC2.
Step 1 : Login with your IAM user
For this project you'll need your IAM user, not your root user, if you already logged in as your IAM user, skip straight to step 2!
Log In with your IAM Admin User.
If you've logged in successfully as your IAM User, skip to the next step.
If you don't have an IAM user set up - no worries!
Here are the steps to create one:
Head to your AWS Account as the root user.
Open the
AWS IAM
console.From the left hand navigation panel, choose
Users
.Choose
Create user
.For the User name, use
Yourname-IAM-Admin
.Make sure to select the checkbox next to
Provide user access to the AWS Management Console - optional.
This does not apply to all accounts, but if you're prompted with a pop up panel that says.
Are you providing access to a person?
, chooseI want to create an IAM user.
For the console password, choose
Custom password
.Type in a password that you will be able to remember/access in the future.
Deselect the checkbox for
Users must create a new password at next sign-in - Recommended
.Choose
Next
.In the permissions set up page, choose
Attach policies directly
.From the list of
Permissions policies
, selectAdministratorAccess
.Choose
Next
.Choose
Create user
.Voilà - you've just created your new user! Stay on this page.
Choose
Download .csv file
Copy the
Console sign-in URL
.Now you're ready to start using your IAM user.
Log out of your root user's AWS Account.
Paste and go to your copied console sign-in URL.
Open your downloaded .csv file containing your user's access instructions.
Log in using your IAM user's username and password in the .csv file.
Step 2 : Create an Aurora MySQL Database
In this step, you are going to:
Create an Aurora relational database from scratch.
What is Aurora Database? How is it different from other databases?
AWS Aurora is a type of relational database. As you can tell form the first few steps of creating a relational database, there are plenty of optins to choose from!
We'd use AWS Aurora if we needed something large scale, with peak performance and uptime. This is because Aurora databases use Clusters . Ordinary relational databases, they suit smaller databases and less demanding workloads.
Let's create your Aurora database:
Head to RDS console - search for
rds
in search bar at the top of the screen.Notice that even if you search for
Aurora
, the same result shows up!In the left navigation bar, select Databases.
In the Database section, select Create Database.
On the Create database page, choose Standard Create.
In the Configuration section, make the following changes:
For Engine type, choose Aurora (MySQL Compatible).
What is engine type?
The engine type is like the core software that powers our database. Imagine it as the operating syste of a computer, but for databases.
For Engine Version, choose Aurora MySQL 3.05.2 (compatible with MySQL 8.0.32) - default for major version 8.0.
What is Engine Version?
The engine version is like choosing the specific version of software that your database will use. For example, Aurora MySQL 3.05.2 (compatible with MySQL 8.0.32) is a specific version of Aurora that's compatible with a particular MySQL version (8.0.32).
For Templates, choose Dev/Test.
What are Templetes?
Templates are pre-set settings that help you quickly set up your database environment according to your needs. It's basically AWS helping you make selections for the rest of this set-up page! The Dev/Test template is designed for development and testing environments, helping you pick lower cost options.
In the Settings section, set these values:
DB cluster identifier :
my-db-cluster
.Master username:
admin
.For Credentials management select Self managed.
Master password : set a password.
Confirm password : retype the password.
Make sure you save your database login details soemwhere safe!
-
Leave the Cluster storage configuration settings as default.
In the Instance configuration section, set these values:
Burstable classes (includes t classes)
db.t3.medium
What is Instance configuration?
Instance configuration is where we can select the type of virtual computer that our Aurora database will run on.
The instance type that we choose determines how powerful, and how much memory, our virtual computer has. The more powerful it is, the better it will perform - but also more expensive the price!
The Burstable classes are cost-effective types of database instances that are best when you have a consistent baseline level of traffic with occassional, random spikes in demand... a sudden "burst" of traffic.
In the Availability and durability section, use the default values.
In the Connectivity section, the first thing it asks is whether we need to connect to an EC2 instance.
For Compute resource, choose Connect to an EC2 compute resource.
Now select the drop down for EC2 instance, and choose, huh! We haven't created an EC2 instance. Let's do that first then come back to this.
Why do we need an EC2 instance to be a web app server?
Any web app needs to run on a computer. But do we need to have a physical computer to do this?
Well No! We're going to use a virtual computer that we rent through AWS.
This is what an EC2 instance is for. An EC2 instance as a rented virtual computer that you use to run your web app. It is the place where all processing, data handling, and user interactions happen.
Step 4: Launch an EC2 Instance
In this step, we're going to create an Amazon EC2 instance using our default VPC and default subnets.
In this step, you're going to :
Create an EC2 instance to host a web app
Open a new tab in your web browser and go to your AWS console (this means we can keep our Aurora database set-up in progress!)
In the upper-right corner of the AWS Management Console, make sure your AWS Region is the same as that in your Aurora database creation.
In the AWS console search bar, search for EC2.
Select Instances in the left hand menu and choose Launch instances.
Choose the following settings in the Launch an instance page.
Under Name and tags, for Name, enter
My-ec2-instance-web-server
Under Application and OS Images (Amazon Machine Image), choose Amazon Linux.
Choose the Amazon Linux 2023 AMI.
Keep the defaults for the other choices.
Under Instance type, choose t2.micro.
Under Key pair (login), choose a Create new key pair.
For your Key pair name, enter
MyAuroraApp
Leave your Key pair type as RSS
Leave your Private key file format as .pem since we're using SSH later on to access our EC2 instance.
Select Create key pair.
Back in our EC2 creation, under Network settings, set these values and keep the other values as their defaults:
- For Allow SSH traffic from, choose your IP address if it's correct (you can check your IP by clicking here). Otherwise select Anywhere.
Check the boxes for Allow HTTP traffic from the internet.
Leave the default values for the remaining sections.
Review the summary panel of your instance configuration.
When you're ready, choose Launch instance.
Navigate back to your list of EC2 instances, and then select the checkbox next to your new instance.
In the Details tab, note the following important details:
In Instance summary, note the Public IPv4 DNS.
Note the value for Key pair name.
Wait until Instance state for your instance is Running before continuing.
Step 4: Finish Creating your Aurora Database
Nice work! Now that we've got our EC2 instance ready to go, we can go back to creating our Aurora database. This time, we'll connect it to our new EC2 instance.
Navigate back to your open tab that you were creating our Aurora database in.
We were up to the Connectivity section. But this time we have one big advantage...we have an EC2 instance! Woohoo!
For Compute resource, choose Connect to an EC2 compute resource.
Now select the drop down for EC2 instance, and choose my-ec2-instance-web-server.
NOTE: You may need to select the refresh button to the right of the EC2 instance drop-down.
Scroll down and open the Additonal configuration section.
Enter sample for inital database name.
Keep the default settings for the other options.
Select Create database.
Close any pop-ups that appear.
Your new DB cluster will show in the Databases list with the status Creating.
Do you notice that your database has the name my-db-cluster and there are two of them? Why is that?
Whats this 'database cluster business?
A database cluster in Aurora is a group of database copies that network together so your data is always available.
Each cluster consits of a primary instance and muliple read replicas as back-ups. If your database's primary instance fails, one of the replicas can be promoted to primary automatically.
Wait for the Status of your new DB cluster to show as Available.
Select the DB identifier of your top database to take a look at the details.
Notice that there are two Endpoints in our Database. Cool! This is our cluster in action.
Well done! We.ve created a new relational database and have an EC2 instance waiting for our new web app. Let's build that web app and connect it to our database in the next project!
Summary
Congrats!!! you have finally learned how to create Aurora Relational Database and to connect it with the EC2 instances. In the next project let's launch the web app until then stay tuned...