Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
We could use EC2 to run instances that have a database installed on them, so that we’d have two different types of instances: the ones running the web app itself using Flask (and no database), and the ones running the database only. However, the AWS Relational Database Service (RDS) provides us with a managed database service that runs in the cloud, which has several advantages: it easily scales, provides high availability and data resiliency, and we don’t have to manage the servers ourselves (e.g., dealing with updates and patches to the OS and database software over time).
In this lab, you are going to update the MiniTwit application to use RDS instead of the oninstance database, and you’re going to deploy your new MiniTwit and RDS database in AWS.
To create an RDS database, go to the RDS service in the AWS Management Console. Click on the “Create Database” button. RDS lets you choose which DB engine you want to use – we’ll use MySQL for this assignment. Select “MySQL” and also go ahead and check “Only enable options eligible for RDS Free Usage Tier” at the bottom of the page as well, then click “Next”. On the next page, choose the “db.t2.micro” (Note: t2, not t3) instance type – this is probably the default.
Leave the rest of the Instance specifications section at the default values, but scroll down to the Settings section to configure your database. Give your database an instance identifier (this is the name of your RDS instance, not the name of the database hosted on the RDS instance), and choose a username and password for connecting to the database, then click “Next”.
On the final page, choose the “Default VPC” for your Virtual Private Cloud (VPC) and “No” for public accessibility (i.e., the DB should not be publicly accessible! Only your EC2 instances will be able to connect to it.). For the Availability Zone, you can choose “No preference” and for the VPC security groups, you should choose “Select existing VPC security groups” and then the default. In the Database Options section, give the database a name (this is the actual name of your database), and leave the rest of the options as their defaults. Everything after that can also stay at its defaults. Then click the “Create database” button!
It will take a minute to start up, but once it does, take a little time to explore the RDS Console and see what it shows you about your new database.
Warning: You are charged per hour for each RDS instance you have running. Just like your EC2 instances, you shouldn’t leave RDS instances or clusters running for hours and hours without a good reason. Be sure to shut down your RDS instances and clusters when you’re done for the day. (Yes, that does mean you lose your data, but that should be okay for class assignment purposes.)
Note: MySQL databases don’t currently support the “Stop” option. You will need to “Delete” them instead – this means all the data stored in them will be deleted. This probably isn’t a big deal for the assignment, since we’re just creating test data, not real users or tweets. However, if you do want to preserve your data, you can take a “snapshot” of your database, and then restore that snapshot when you start up new instances again.