title: python (boto3) program to delete old snapshots in aws
body: <p>I have already written a program to delete old snapshots.But the problem for me now is if the snapshot is attached with an ami then it doesn't get deleted and the program also stops.It displays the following message :</p>
  
  <blockquote>
    <p><strong>botocore.exceptions.ClientError: An error occurred (InvalidSnapshot.InUse) when calling the DeleteSnapshot operation: The snapshot snap-12345678 is currently in use by ami-12345</strong></p>
  </blockquote>
  
  <p>I want the program to skip those snapshots alone and continue to delete other snapshots. here is my code below:</p>
  
  <pre><code>import boto3
  import datetime
  client = boto3.client('ec2',region_name='us-west-1')
  snapshots = client.describe_snapshots(OwnerIds=['12345678'])
  for snapshot in snapshots['Snapshots']:
      a= snapshot['StartTime']
      b=a.date()
      c=datetime.datetime.now().date()
      d=c-b
      if d.days&gt;10:
          id = snapshot['SnapshotId']
          client.delete_snapshot(SnapshotId=id)
  </code></pre>