如何使用Name键显示快照?

时间:2017-03-07 20:05:27

标签: python amazon-web-services boto3

我想设置我的区域并显示以名称Snaps开头的所有快照。我得到了该区域,但如何获取显示我的快照的名称键? 这是我到目前为止所做的:

import boto3
my_session = boto3.session.Session(region_name = 'us-east-1')
my_region = my_session.region_name
ec2 = boto3.resource('ec2')

感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

describe_snapshots中使用Filters

my_session = boto3.session.Session(region_name = 'us-east-1')
ec2 = my_session.client('ec2')
snapshot_response = ec2.describe_snapshots(Filters=[{'Name': 'tag:Name', 'Values': ['Snaps*']}])

# To print only the Name of the snapshots
for snapshot in snapshot_response['Snapshots']:
    for tag in snapshot['Tags']:
        if tag['Key'] == 'Name':
            print tag['Value']
            break