简体   繁体   English

如何使用boto3通过OwnerIds和Filters描述快照

[英]How to describe snapshots by OwnerIds and Filters using boto3

How to describe snapshots owned by me and filtering by tag simultaneously? 如何描述我拥有的快照并同时按标签过滤?

It describe snapshots owned by me with code below: 它通过以下代码描述了我拥有的快照:

import boto3
region_src = 'us-east-1'
client_src = boto3.client('ec2', region_name=region_src)

def get_snapshots_src():
    response = client_src.describe_snapshots(OwnerIds=['012345678900'])
    return response["Snapshots"]

snap = get_snapshots_src()
print(*snap, sep="\n")

But when I add "Filters", its starts ignoring "OwnerIds" and filtering only by tag. 但是,当我添加“过滤器”时,它开始忽略“ OwnerIds”,仅按标记过滤。

client_src.describe_snapshots(OwnerIds=['012345678900'],Filters=[{'Name': 'tag:Disaster_Recovery', 'Values': ['Full']}])

I'm follow an official boto3 documentation: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#EC2.Client.describe_snapshots 我遵循官方的boto3文档: https ://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#EC2.Client.describe_snapshots

I think the Filters and OwnerIds options are working separately. 我认为Filters和OwnerIds选项是分开工作的。 I expect that the OwnerIds option is an abbreviation of the Filters option for owner-id, because I also got the result that the OwnerIds option is ignored. 我希望OwnerIds选项是owner-id的Filters选项的缩写,因为我还得到了OwnerIds选项被忽略的结果。

And so, you can use the filter option such as 因此,您可以使用过滤器选项,例如

    Filters=[
        {
            'Name': 'tag:key',
            'Values': [
                'value'
            ]
        },
        {
            'Name': 'owner-id',
            'Values': [
                'value'
            ]
        }
    ]

and it will work well same as me. 它会和我一样很好地工作。


Filters (list) --
The filters.

description - A description of the snapshot.
encrypted - Indicates whether the snapshot is encrypted (true | false )
owner-alias - Value from an Amazon-maintained list (amazon | self | all | aws-marketplace | microsoft ) of snapshot owners. Not to be confused with the user-configured AWS account alias, which is set from the IAM console.
owner-id - The ID of the AWS account that owns the snapshot.
progress - The progress of the snapshot, as a percentage (for example, 80%).
snapshot-id - The snapshot ID.
start-time - The time stamp when the snapshot was initiated.
status - The status of the snapshot (pending | completed | error ).
tag :<key> - The key/value combination of a tag assigned to the resource. Use the tag key in the filter name and the tag value as the filter value. For example, to find all resources that have a tag with the key Owner and the value TeamA , specify tag:Owner for the filter name and TeamA for the filter value.
tag-key - The key of a tag assigned to the resource. Use this filter to find all resources assigned a tag with a specific key, regardless of the tag value.
volume-id - The ID of the volume the snapshot is for.
volume-size - The size of the volume, in GiB.
(dict) --
A filter name and value pair that is used to return a more specific list of results from a describe operation. Filters can be used to match a set of resources by specific criteria, such as tags, attributes, or IDs. The filters supported by a describe operation are documented with the describe operation.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM