1

Background: I am very new to the AWS Management Console, and I just created a very simple AWS Lambda function(Python 3.7) that deletes EBS Volume Snapshots based on a time limit. I also created a CloudWatch event to trigger the function every hour of the day. This works well for a few volumes, but with additions of volumes, this causes cost / speed issues.

Question: I am trying to update my EBS Snapshot Deletion lambda function code to find the rate limit of requests to avoid throttling, and use that to create an exponential backoff/retry model for the program(making the program scalable no matter how many snapshots there are). I would assume there is a special API call that can help me with this, but I have not been able to find any concrete information online. Any help would be much appreciated! Pasting my current code below:

import boto3
from datetime import datetime, timezone, timedelta
ec2=boto3.resource('ec2') #resource, higher level
snapshots = ec2.snapshots.filter(OwnerIds=['self']) #all snapshots owned by me, returns list

def lambda_handler(event, context):
# TODO implement
for i in snapshots:#for each snapshot
    start_time=i.start_time #timestamp when snapshot was initiated
    delete_time=datetime.now(tz=timezone.utc)-timedelta(days=1) #Correct time in UTC timezone - 1 days]
    if delete_time>start_time:#if delete time is more than start time (more than a day)
        i.delete() #call method to delete that snapshot
        print ('Snapshot with Id = {snaps} is deleted'.format(snaps=i.snapshot_id)) #pull ID that was deleted

0 Answers0