title: Delete all keys in a bucket of s3 which are three days old using python
body: <p>How do I delete all the keys in an S3 bucket which are three days old using python?</p>
  
  <p>S3 bucket contents are like: </p>
  
  <pre><code>mybucket001/backup/1566394660_21_08_2019_backup
  mybucket001/backup/1566394660_20_08_2019_backup
  mybucket001/backup/1566394660_19_08_2019_backup
  mybucket001/backup/1566394660_18_08_2019_backup
  </code></pre>
  
  <p>I need to keep only the last two days of data.</p>
  
  <p>Here is what I tried: </p>
  
  <pre><code>import boto
  
  from boto.s3.key import Key
  
  keyId='***'
  sKeyId='***'
  
  srcFileName="file name" #Name of the file to be deleted
  
  bucketName="bucket name" #Name of the bucket, where the file resides
  
  conn = boto.connect_s3(keyId,sKeyId) #Connect to S3
  
  bucket = conn.get_bucket(bucketName) #Get the bucket object
  
  k = Key(bucket,srcFileName) #Get the key of the given object
  
  k.delete()
  
  </code></pre>