0

I am trying to filter snapshots based on description using boto3, but the description filter doesn't seem to work. See below:

>>> ec2.describe_snapshots(Filters=[{'Name':'snapshot-id','Values':['snap-yyyy']}],MaxResults=10,OwnerIds=['xxxxx'])['Snapshots']
[{u'Description': 'snap-yyyy blah blah', u'VolumeSize': 100, u'VolumeId': 'vol-ffffffff', u'State': 'completed', u'StartTime': datetime.datetime(2018, 6, 12, 9, 59, 16, tzinfo=tzutc()), u'Progress': '100%', u'OwnerId': 'xxxxx', u'SnapshotId': 'snap-yyyy'}]

If I then take the snapshot description and use that to search, I get nothing back:

>>> ec2.describe_snapshots(Filters=[{'Name':'description','Values':['snap-yyyy blah blah']}],MaxResults=10,OwnerIds=['xxxxx'])['Snapshots']
[]

OwnerId and snapshotId has been redacted, but VolumeId is actually vol-fffffff due to the snapshot being a copy of a snapshot from a different region.

Is there a reason that a description filter doesn't match? According to the docs, description is a valid field to filter by - https://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Client.describe_snapshots

Brett
  • 5,690
  • 6
  • 36
  • 63

1 Answers1

1

Call describe_snapshots() without passing MaxResults and OwnerIds. Call it with just the filter with description

helloV
  • 50,176
  • 7
  • 137
  • 145
  • To confirm, with further investigation, it seems to be the way initial resultsets are passed through the filters / describe parameters. I was not checking the `NextToken` - but if I have a whole lot of snapshots and set `MaxResults` to 10 with a description filter, I might not get any matched (by filter) in the first 10 - but will get 0 results back (i.e. the first 10 snapshots didn't match filter). – Brett Jun 14 '18 at 15:39