Professional Documents
Culture Documents
Instructions For How To Set Up and Run The API On An EC2 Instance and Connect To RDS MySQL
Instructions For How To Set Up and Run The API On An EC2 Instance and Connect To RDS MySQL
Instructions For How To Set Up and Run The API On An EC2 Instance and Connect To RDS MySQL
Connect to your EC2 instance using SSH and install the required software packages, such as Python,
Flask, and mysql-connector-python:
3) Copy your Flask application code to the EC2 instance, for example using SCP:
python3 your-code
Get the endpoint, username, and password for your RDS MySQL instance from the AWS Management
Console
Modify your Flask application code to use these credentials to connect to the database, for example:
db = mysql.connector.connect(
host="your-rds-mysql-endpoint",
user="your-rds-mysql-username",
password="your-rds-mysql-password",
database="your-rds-mysql-database"
)
GET http://your-ec2-instance:5000/weather_data/New%20York
POST http://your-ec2-instance:5000/weather_data { "city_name": "San Francisco", "temperature": 65.0,
"humidity": 60.0, "pressure": 1013.0, "wind_speed": 10.0 }
PUT http://your-ec2-instance:5000/weather_data/San%20Francisco { "temperature": 70.0, "humidity":
55.0, "pressure": 1015.0, "wind_speed": 12.0 }
DELETE http://your-ec2-instance:5000/weather_data/San%20Francisco
Create a new Lambda function using the AWS Management Console or the AWS CLI
Write the code for your Lambda function to retrieve weather data from a weather API and update the
MySQL database using the mysql-connector-python library
Set up a CloudWatch Events rule to trigger your Lambda function at the desired intervals, such as every
30 minutes
That's it! With these steps, you should be able to set up and run your Flask API on an EC2 instance and
connect to RDS MySQL.