TerminalDilettante TerminalDilettante - 4 years ago 65
Python Question

How to get list of all EBS Snapshots "started" before a certain date?

I am writing a Python program to get a list of all the EBS snapshots in our account (owner=self) that were "started" (basically, created) before a certain date, then perform some other actions on that list.

I don't think I can use filters in the get_all_snapshots() function because it only supports equality, not GT/LT operators. I believe AWS boto Get Snapshots in Time Period confirms this.

So I supposed I have to get a list of all of them, then iterate through the list. However, the boto documentation isn't clear to me (http://boto.readthedocs.org/en/latest/ref/ec2.html#module-boto.ec2.snapshot) exactly what methods/properties are available on the snapshot object.

Any guidance here?

Answer Source

Get a connection:

conn = boto.ec2.connect_to_region("us-east-1")

Get your snapshots:

snaps = conn.get_all_snapshots(owner="self")

Iterate through the list and look at the start_time attribute: snaps[0].start_time

Use dir(snaps[0]) to see all available attributes and find other things you need.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download