Develop and deploy an AWS Lambda function capable of securely connecting to a MySQL database hosted on a private EC2 instance and retrieving user activity data (e.g. from the locations
table)
mysql2
librarya****@'%'
created with read privilegesconfig.json
(to be migrated to environment variables or Secrets Manager)AWS Lambda is like a smart helper that only wakes up to do a task when needed, so you donβt have to keep your computer on all day
Plus, it scales up automatically (AWS handles this) so no need to manage a separate server.
In our case, we use it to securely connect to the database hosted by a private EC2 instance.
Since the MySQL DB is inside a private VPC, we can deploy a lambda function inside the same VPC so that the lambda function can safely connect to the database through private networking.
Lambda can act as the middleman between those services and your database.
**React Native App**
β (HTTP POST with device_id)
**API Gateway**
β (Triggers Lambda function)
**AWS Lambda Function**
β (Executes SQL query using device_id)
**MySQL Database on EC2**
β (Returns 2000 latest rows to Lambda)
**AWS Lambda Function**
β (Builds and returns JSON response)
**API Gateway**
β (Returns HTTP response to app)
**React Native App**