How to take RDS Snapshots using Lambda?

Published on: April 22, 2019 by Smith Nevil

How to take RDS Snapshots using Lambda?


Amazon Relational Database Service (Amazon RDS) is a web service that makes it easier to set up, operate, and scale a relational database in the cloud. It provides cost-efficient, resizable capacity and can manage common database administration tasks. If your site/application stores its sensitive data in the database, you will definitely want to back up that information so that it can be restored in case of any disaster.

Manual backups for RDS can be configured and scheduled. Thought of doing it the lambda way and below is a working script for the same. Code is originally developed by another author and shared at

Below is the python code. The Lambda function is set to run every day using CloudWatch Event Scheduler. All we did was to create a trigger by connecting a CloudWatch event, where it is set up as a cron command, to the Lambda function.

The retention period is set as 7 days and also change the DBInstance identifier as the one in your RDS instance. Below code worked at the time of writing, but if it is not, please comment below.



import datetime

def lambda_handler(event, context):

print("Connecting to RDS")

client = boto3.client('rds')

print("RDS snapshot backups stated at %s...\n" %



DBSnapshotIdentifier='web-platform-%s' %"%y-%m-%d-%H"),



'Key': 'CostCenter',

'Value': 'web'




for snapshot in



if create_ts < -


print "Deleting snapshot id:", snapshot['DBSnapshotIdentifier']




This is my solution to take RDS Snapshots using Lambda.

Infrastructure operations are quite complex and require a high level of technical competency. Our team of specially trained infrastructure consultants provides expert cloud infrastructure management for all levels of operations.


Category : Backup management, Sever management

Smith Nevil

Smith Nevil

Smith is always ready to learn new technologies and explore new territories. His never-ending passion towards technological advancements, unyielding affinity to perfection and excitement in the exploration of new areas, help him to be on the top of everything he is involved with. He is currently working as System Engineer at SupportSages.

You may also read:


Add new commentSIGN IN

Let's Connect


Your Cart

Cart is empty.

Send this to a friend