@@ -21,7 +21,8 @@ def lambda_handler(event, context):
21
21
22
22
print "Found %d instances that need backing up" % len (instances )
23
23
24
- to_tag = collections .defaultdict (list )
24
+ to_tag_retention = collections .defaultdict (list )
25
+ to_tag_mount_point = collections .defaultdict (list )
25
26
26
27
for instance in instances :
27
28
try :
@@ -43,9 +44,10 @@ def lambda_handler(event, context):
43
44
VolumeId = vol_id ,
44
45
Description = instance ['InstanceId' ],
45
46
)
46
-
47
- to_tag [retention_days ].append (snap ['SnapshotId' ])
48
-
47
+
48
+ to_tag_retention [retention_days ].append (snap ['SnapshotId' ])
49
+ to_tag_mount_point [vol_id ].append (snap ['SnapshotId' ])
50
+
49
51
50
52
print "Retaining snapshot %s of volume %s from instance %s for %d days" % (
51
53
snap ['SnapshotId' ],
@@ -55,20 +57,19 @@ def lambda_handler(event, context):
55
57
)
56
58
57
59
ec .create_tags (
58
- Resources = to_tag [ retention_days ],
60
+ Resources = to_tag_mount_point [ vol_id ],
59
61
Tags = [
60
62
{'Key' : 'Name' , 'Value' : dev_attachment },
61
63
]
62
64
)
63
65
64
- for retention_days in to_tag .keys ():
66
+ for retention_days in to_tag_retention .keys ():
65
67
delete_date = datetime .date .today () + datetime .timedelta (days = retention_days )
66
68
delete_fmt = delete_date .strftime ('%Y-%m-%d' )
67
- print "Will delete %d snapshots on %s" % (len (to_tag [retention_days ]), delete_fmt )
69
+ print "Will delete %d snapshots on %s" % (len (to_tag_retention [retention_days ]), delete_fmt )
68
70
ec .create_tags (
69
- Resources = to_tag [retention_days ],
71
+ Resources = to_tag_retention [retention_days ],
70
72
Tags = [
71
73
{'Key' : 'DeleteOn' , 'Value' : delete_fmt },
72
74
]
73
75
)
74
-
0 commit comments