title: Boto3 and AWS Lambda - deleting snapshots older than
body: <p>I'm currently utilising AWS Lambda to create snapshots of my database and delete snapshots older than 6 days.  I'm using the Boto3 library to interface with the AWS API. I'm using a CloudWatch rule to trigger the deletion code every day. </p>
  
  <p>Normally this is working fine, but I've come across an issue where at the start of the month (first 6 days) the delete script does not appear to delete any snapshots, even though snapshots older than 6 days exist. </p>
  
  <p>The code is below: </p>
  
  <pre><code>import json
  import boto3
  from datetime import datetime, timedelta, tzinfo
  
  class Zone(tzinfo):
      def __init__(self,offset,isdst,name):
          self.offset = offset
          self.isdst = isdst
          self.name = name
      def utcoffset(self, dt):
          return timedelta(hours=self.offset) + self.dst(dt)
      def dst(self, dt):
          return timedelta(hours=1) if self.isdst else timedelta(0)
      def tzname(self,dt):
          return self.name
  
  UTC = Zone(10,False,'UTC')
  
  # Setting retention period of 6 days
  retentionDate = datetime.now(UTC) - timedelta(days=6)
  
  def lambda_handler(event, context):
      print("Connecting to RDS")
      rds = boto3.setup_default_session(region_name='ap-southeast-2')
      client = boto3.client('rds')
      snapshots = client.describe_db_snapshots(SnapshotType='manual')
      print('Deleting all DB Snapshots older than %s' % retentionDate)
  
      for i in snapshots['DBSnapshots']:
          if i['SnapshotCreateTime'] &lt; retentionDate:
              print ('Deleting snapshot %s' % i['DBSnapshotIdentifier'])
                client.delete_db_snapshot(DBSnapshotIdentifier=i['DBSnapshotIdentifier']
          )
  </code></pre>