AWS Lambda RDS Snapshot Copies – Long term backups

AWS’s managed database service is pretty awesome. Its a managed service that takes care of the heavy lifting for managing a database server letting you focus on running your application rather than managing a database server. The service provides patching, automated backups etc.

A nice feature of the AWS RDS service is automated backups. The service will create automated backups on the schedule you desire (daily, weekly etc.) and gives you up to 35 days of backup retention. But what if you need more than 35 days of database backups?

Do you create your own backups manually? Ah, nope. Manually means its not going to get done. Do you schedule native backups? Ah, while somewhat possible, its not very elegant. How about using Lambda? Yes! Serverless code. But how?

Using this python lambda script and the AWS python API’s you can copy the current latest RDS snapshot and maintain a weekly retention history that suits your needs. Likewise, you also might need to retain a long term history of monthly backups. We got you covered with that as well.

Here is a snippet of the documentation that describes the scripts functionality:

rds-copy-snapshots-lambda: Makes a copy of the most recent auto snapshot and deletes ones older than the set retention period.

There are two versions of the script: a weekly version and a monthly version. You can choose to use only weekly, monthly, or both of them as you see fit.

Weekly and Monthly Snapshots are named and tagged differently to allow for filtering by type as well as to prevent inadvertent deletion.

More details about the rds-copy-snapshots-lambda function can be found here: https://github.com/swmacdonald/rds-copy-snapshots-lambda