Deploy Employee management application on AWS using: Ec2, Iam, S3,RDS,Route53
Project Overview
We will be deploying a Flask-based web application for employee management or registration, integrating MySQL and AWS S3 for database and file storage, respectively.
Steps to cover:
Create MySQL database in AWS RDS
Create EC2 instance
Create MySQL database in AWS RDS
Go to rds and select MySQL
Make sure to select free tire version for this project purpose
Now name the db as MySQL as an identifier and also keep username and password. Also disable enable storage autoscaling option for mow and enable public access and then create database
Once database status is available then, your db is created name MySQL
Create S3 bucket
Got to amazon s3 > bucket> create a bucket and keep bucket name as employee data and check the Block Public Access settings for this bucket and create a bucket.
Block Public Access settings for this bucket
Set public access rule in S3
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::Bucket-Name/*"
]
}
]
}
Give Admin access to EC2 instance by creating a rule in IAM
IAM > Roles > Create role > Select Ec2 in use cases and give AdministratorAccess and create a role name employee-vm-role
Create EC2 instance
Make a t2.micro instance with Ubuntu 22.04 and launch the instance.
Now we have to give AdministratorAccess to your ec2 instance that er have created earlier in Iam role
Instance > Actions > Security > Modify IAM role > Select role from drop down and Update Iam role
SSH to our Ec2 server and connect to our rds first to check we can access to our database from our server
Take ssh and update server and install MySQL client to connect with db with:
apt-get update
sudo apt-get install mysql-client
Once done go to RDS and copy Endpoint of your DB, which will be used to connect to your database
enter the endpoint URL to your ec2 server to connect to DB with
mysql -h mysql.c0fbjpomvr0y.us-east-1.rds.amazonaws.com -u admin -p
Create a database name employee
Now create a table name employee and insert the below table
USE employee;
CREATE TABLE employee(
empid varchar(20),
fname varchar(20),
lname varchar(20),
pre_skill varchar(20),
location varchar(20)
);
You check to verify table with SHOW TABLES;
Now exit the database with exit
command and clone the below repository with
git clone https://github.com/Pratik1795/aws-live.git
now go to app aws-live and modify configpy file with
vi config.py
Fill in your all necessary details in this file
customhost = "RDS endpoint URL"
customuser = "DB username"
custompass = "DB password"
customdb = "DB name"
custombucket = "S3 bucket name "
customregion = "Region"
Install the below packages on instance
sudo apt-get install python3
sudo apt-get install python3-flask
sudo apt-get install python3-pymysql
sudo apt-get install python3-boto3
And by running below command your application will run
python3 EmpApp.py
Browse public IP and try entering data in it this data will be stored in your DB and image will be stored to your S3 bucket
Check db table select * from employee; and also check objects in bucket
To point a domain to Amazon Route 53, follow these steps:
Access Route 53: Navigate to the "Route 53" service by either searching for it in the AWS Management Console or directly selecting it from the list of services.
Create a Hosted Zone:
Click on "Create Hosted Zone." Enter your domain name (e.g., example.com) and click "Create." Retrieve Name Servers:
After creating the hosted zone, you will be provided with a set of name servers. These are the DNS servers you need to use for your domain. Access Domain Registrar:
Go to your domain registrar's website (where you purchased your domain). Log in to your account. Modify DNS Settings:
Find the DNS management or domain settings section in your registrar's control panel. Look for options to set custom or external DNS servers. Replace the existing DNS servers with the ones provided by Route 53. Save Changes:
Save the changes in your domain registrar's control panel. Wait for Propagation:
DNS changes may take some time to propagate worldwide. It usually takes a few minutes to a few hours, but in some cases, it can take up to 48 hours for the changes to take effect. Verify Configuration:
Once the DNS changes have propagated, you can use DNS lookup tools or online services to verify that your domain is now pointing to the Route 53 name servers. Configure DNS Records (Optional):
Back in the Route 53 console, you can configure DNS records (e.g., A, CNAME) to direct traffic to specific resources such as an EC2 instance. That's it! Your domain is now pointed to Amazon Route 53, and you can use Route 53 to manage the DNS records for your domain.