title: Delete Orphan Snapshots that are older - Script
body: <p>I have the following script to delete the snapshots that are 12 months old. But this deletes all snapshots that are older than 12 months. I have to identify the Orphan Snapshots that are 12 months and delete only the Orphan snapshots and not AMI Snapshots. </p>
  
  <p>This Script deletes all snapshots that are 12 months old.</p>
  
  <ol>
  <li>I want to identify and delete the orphan snapshots that are 12 months old, but this script deletes all snapshots older than 12 months.</li>
  </ol>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>import boto 
  import datetime
  import dateutil
  from dateutil import parser
  from boto import ec2
   
  connection=ec2.connect_to_region("REGION-NAME")
   
  ebsAllSnapshots=connection.get_all_snapshots(owner='16-DIGIT-AWS-ACCOUNT-NUMBER')
   
  #Get the 30 days old date
  timeLimit=datetime.datetime.now() - datetime.timedelta(days=365)  
   
  for snapshot in ebsAllSnapshots:
       
      if parser.parse(snapshot.start_time).date() &lt;= timeLimit.date():
          print " Deleting Snapshot %s  %s "  %(snapshot.id,snapshot.tags)
          connection.delete_snapshot(snapshot.id) 
      else:
          # this section will have all snapshots which is created before 30 days
          print "Only Deleting Snapshots which is 365 days old"</code></pre>
  </div>
  </div>
  </p>