Create a Python-based Lambda function to handle the three steps. The function uses environment variables for sensitive information (e.g., database credentials, S3 bucket) and a custom layer for mysqldump and mysql binaries. The function is split into three tasks based on the time of execution (:00, :05, :15), determined by an EventBridge event.
Schedule with EventBridge
EventBridge rules trigger the Lambda function at specific minutes (:00, :05, :15) each hour. Each rule passes a payload to indicate the task (dump, upload, or restore).
Lambda Function Code
The Lambda function executes the appropriate task based on the event input. It:
Dumps the MySQL database to a file and compresses it using gzip.
Uploads the compressed file to S3.
Downloads the latest backup from S3 and restores it to RDS.