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 : botocore.exceptions.ClientError:调用DeleteSnapshot操作时发生错误(InvalidSnapshot.InUse):ami-12345当前正在使用快照snap-12345678 我希望程序仅跳过那些快照,然后继续删除其他快照.这是我的代码如下:I want the program to skip those snapshots alone and continue to delete other snapshots. here is my code below:import boto3import datetimeclient = 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>10: id = snapshot['SnapshotId'] client.delete_snapshot(SnapshotId=id)推荐答案我已经自己解决了.这是代码:I've solved it myself. here is the 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 try: if d.days>10: id = snapshot['SnapshotId'] client.delete_snapshot(SnapshotId=id) except Exception,e: if 'InvalidSnapshot.InUse' in e.message: print "skipping this snapshot" continue 这篇关于python(boto3)程序删除aws中的旧快照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-23 07:59