2
2
3
3
import boto3
4
4
from datetime import datetime
5
- import sys
5
+ import sys , traceback
6
6
import logging
7
7
import json
8
8
import pytz
@@ -43,6 +43,9 @@ def list_snapshots_for_resource(self, resource):
43
43
def resolve_backupable_id (self , resource ):
44
44
pass
45
45
46
+ def resolve_snapshot_name (self , resource ):
47
+ pass
48
+
46
49
def resolve_snapshot_time (self , resource ):
47
50
return resource ['StartTime' ]
48
51
@@ -86,9 +89,12 @@ def process_backup(self):
86
89
self .snapshot_resource (resource = backup_item , description = description , tags = tags_volume )
87
90
self .message += ' New Snapshot created with description: %s and tags: %s\n ' % (description , str (tags_volume ))
88
91
total_creates += 1
89
- except Exception , e :
92
+ except Exception as e :
90
93
print ("Unexpected error:" , sys .exc_info ()[0 ])
91
94
print (e )
95
+ exc_type , exc_value , exc_traceback = sys .exc_info ()
96
+ traceback .print_exception (exc_type , exc_value , exc_traceback ,
97
+ limit = 2 , file = sys .stdout )
92
98
pass
93
99
94
100
snapshots = self .list_snapshots_for_resource (resource = backup_item )
@@ -123,6 +129,9 @@ def process_backup(self):
123
129
except Exception as ex :
124
130
print ("Unexpected error:" , sys .exc_info ()[0 ])
125
131
print (ex )
132
+ exc_type , exc_value , exc_traceback = sys .exc_info ()
133
+ traceback .print_exception (exc_type , exc_value , exc_traceback ,
134
+ limit = 2 , file = sys .stdout )
126
135
logging .error ('Error in processing volume with id: ' + backup_id )
127
136
self .errmsg += 'Error in processing volume with id: ' + backup_id
128
137
count_errors += 1
@@ -409,13 +418,6 @@ def lambda_handler(event, context={}):
409
418
410
419
date_suffix = datetime .today ().strftime (period_format )
411
420
412
- sns_boto = None
413
-
414
- # Connect to SNS
415
- if sns_arn or error_sns_arn :
416
- print ('Connecting to SNS' )
417
- sns_boto = boto3 .client ('sns' , region_name = ec2_region_name )
418
-
419
421
result = event
420
422
if ec2_region_name :
421
423
backup_mgr = EC2BackupManager (ec2_region_name = ec2_region_name ,
@@ -431,6 +433,13 @@ def lambda_handler(event, context={}):
431
433
result ["ec2_backup_result" ] = backup_mgr .message
432
434
print ('\n ' + backup_mgr .message + '\n ' )
433
435
436
+ sns_boto = None
437
+
438
+ # Connect to SNS
439
+ if sns_arn or error_sns_arn :
440
+ print ('Connecting to SNS' )
441
+ sns_boto = boto3 .client ('sns' , region_name = ec2_region_name )
442
+
434
443
if error_sns_arn and backup_mgr .errmsg :
435
444
sns_boto .publish (error_sns_arn , 'Error in processing volumes: ' + backup_mgr .errmsg , 'Error with AWS Snapshot' )
436
445
@@ -451,6 +460,13 @@ def lambda_handler(event, context={}):
451
460
result ["rds_backup_result" ] = backup_mgr .message
452
461
print ('\n ' + backup_mgr .message + '\n ' )
453
462
463
+ sns_boto = None
464
+
465
+ # Connect to SNS
466
+ if sns_arn or error_sns_arn :
467
+ print ('Connecting to SNS' )
468
+ sns_boto = boto3 .client ('sns' , region_name = rds_region_name )
469
+
454
470
if error_sns_arn and backup_mgr .errmsg :
455
471
sns_boto .publish (error_sns_arn , 'Error in processing RDS: ' + backup_mgr .errmsg , 'Error with AWS Snapshot' )
456
472
0 commit comments