Tim P Tim P - 8 months ago 102
Python Question

Boto3 - Delete_snapshot not evaluating variables

I'm trying to run boto3 to loop through snapshots older than 14 days.
It can find all the snapshots older than 14 days fine, and I've verified that all that works okay. The problem is when it runs through the dictionary trying to delete, it looks like the function isn't correctly evaluating the variable (See below).

It seems to just include it as a string.

The loop runs through the dict using a "for snapshot in ..." if'ing the tags to find the snapshots ready for deletion. Here's the 'if' part:

if snap_start_time < expiry: # check if it's more than a <expiry> old
print "Deleting Snapshot: " + snapshot['SnapshotId']
response = ec2client.delete_snapshot(

errors here:

Deleting Snapshot: snap-f4f0079d
Traceback (most recent call last):
File "./aws-snap.py", line 27, in <module>
File "/usr/lib/python2.6/site-packages/botocore/client.py", line 159, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/lib/python2.6/site-packages/botocore/client.py", line 494, in _make_api_call
raise ClientError(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InvalidSnapshot.NotFound) when calling the DeleteSnapshot operation: None

Any clues? \o/


I would doubt that the SnapshotId might not be passing as a string. Change the SnapshotId to a string format and pass it for deletion. str(snapshot['SnapshotId'])