[英]How to list snapshots that DONT have a specific tag using Boto3
我正在嘗試查找沒有特定標簽的快照。
對於快照,我想要所有沒有Do-Not-Delete
標簽的快照。 不管標簽的價值是什么。
這就是我現在正在做的事情:
snaps_to_remove = ec2_client.describe_snapshots(OwnerIds=account_ids)
for snap in snaps_to_remove['Snapshots']:
# Remove all snapshots with the tag Do-Not-Delete functionality goes here
print(snap)
我不認為是否有基於負面比較的過濾器。 循環並過濾掉帶有特定標簽的列表的正確方法是什么?
如果快照包含標簽,並且其中一個標簽的鍵為“Do-Not-Delete”,則跳過快照:
snaps_to_remove = ec2_client.describe_snapshots(OwnerIds=account_ids)
for snap in snaps_to_remove['Snapshots']:
# Skip snapshots with a Do-Not-Delete tag
if 'Tags' in snap and [tag for tag in snap['Tags'] if tag['Key'] == 'Do-Not-Delete']:
continue
print(snap)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.