25
25
import os
26
26
27
27
28
+
28
29
def lambda_handler (event , context ):
29
30
LOG_LEVEL = os .getenv ('LOG_LEVEL' )
30
31
logging .getLogger ().setLevel (LOG_LEVEL )
@@ -80,7 +81,7 @@ def assume_role(account_id, role='AWSControlTowerExecution'):
80
81
81
82
# Describe configuration recorder
82
83
configrecorder = configservice .describe_configuration_recorders ()
83
- logging .info (f'Existing Configuration Recorder :' , configrecorder )
84
+ logging .info (f'Existing Configuration Recorder: { configrecorder } ' )
84
85
85
86
# ControlTower created configuration recorder with name "aws-controltower-BaselineConfigRecorder" and we will update just that
86
87
try :
@@ -100,6 +101,9 @@ def assume_role(account_id, role='AWSControlTowerExecution'):
100
101
101
102
# Event = Delete is when stack is deleted, we rollback changed made and leave it as ControlTower Intended
102
103
if event == 'Delete' :
104
+ logging .warn (
105
+ "Deleting stack: Reverting Configuration Recorder to default settings"
106
+ )
103
107
response = configservice .put_configuration_recorder (
104
108
ConfigurationRecorder = {
105
109
'name' : 'aws-controltower-BaselineConfigRecorder' ,
@@ -110,7 +114,9 @@ def assume_role(account_id, role='AWSControlTowerExecution'):
110
114
},
111
115
'recordingMode' : {'recordingFrequency' : 'CONTINUOUS' },
112
116
})
113
- logging .info (f'Response for put_configuration_recorder :{ response } ' )
117
+ logging .info (
118
+ f"Configuration Recorder reset to default. Response: { json .dumps (response , default = str )} "
119
+ )
114
120
115
121
else :
116
122
config_recorder = {
@@ -152,7 +158,7 @@ def assume_role(account_id, role='AWSControlTowerExecution'):
152
158
logging .info (f'Post Change Configuration recorder : { configrecorder } ' )
153
159
154
160
except botocore .exceptions .ClientError as exe :
155
- logging .error ('Unable to Update Config Recorder for Account and Region : ' , account_id , aws_region )
161
+ logging .error (f 'Unable to Update Config Recorder for Account { account_id } and Region { aws_region } ' )
156
162
configrecorder = configservice .describe_configuration_recorders ()
157
163
logging .info (f'Exception : { configrecorder } ' )
158
164
raise exe
0 commit comments