Automate SQL queries with a Python Lambda Function.
This is a lambda function which queries an RDS database, writes the results to an Excel file, and saves the file to an S3 bucket.
- An AWS account
- An RDS database to run the queries against
- Permissions for RDS, Lambda, S3, and EventBridge (CloudWatch Events)
- Clone the repo
lambda.pyto match your specific environment: database connection details, queries you want to run, name your Excel sheets, name the file, and specify the S3 bucket name.
- If you wish to have this run on a schedule, add an EventBridge trigger and specify an interval number of days when this function is executed.
This function is very useful if you have a need to re-run the same SQL queries on a set schedule, like every week or two, or even every day. The Excel file generated could be useful to a business analyst to track any kind of change to your database: number of users, emails for a newsletter, telemetry, etc.