我想设置我的区域并显示以名称Snaps
开头的所有快照。我得到了该区域,但如何获取显示我的快照的名称键?
这是我到目前为止所做的:
import boto3
my_session = boto3.session.Session(region_name = 'us-east-1')
my_region = my_session.region_name
ec2 = boto3.resource('ec2')
感谢任何帮助!
答案 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