Skip to content

Commit f5781a0

Browse files
committed
Use existing AWS Config recorder name to prevent recorder limit exception
1 parent d08e994 commit f5781a0

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

ct_configrecorder_override_consumer.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ def assume_role(account_id, role='AWSControlTowerExecution'):
8080

8181
# Describe configuration recorder
8282
configrecorder = configservice.describe_configuration_recorders()
83-
logging.info(f'Existing Configuration Recorder :', configrecorder)
83+
logging.info(f'Existing Configuration Recorder: {configrecorder}')
84+
85+
# Get the name of the existing recorder if it exists, otherwise use the default name
86+
recorder_name = 'aws-controltower-BaselineConfigRecorder'
87+
if configrecorder and 'ConfigurationRecorders' in configrecorder and len(configrecorder['ConfigurationRecorders']) > 0:
88+
recorder_name = configrecorder['ConfigurationRecorders'][0]['name']
89+
logging.info(f'Using existing recorder name: {recorder_name}')
8490

8591
# ControlTower created configuration recorder with name "aws-controltower-BaselineConfigRecorder" and we will update just that
8692
try:
@@ -102,7 +108,7 @@ def assume_role(account_id, role='AWSControlTowerExecution'):
102108
if event == 'Delete':
103109
response = configservice.put_configuration_recorder(
104110
ConfigurationRecorder={
105-
'name': 'aws-controltower-BaselineConfigRecorder',
111+
'name': recorder_name,
106112
'roleARN': role_arn,
107113
'recordingGroup': {
108114
'allSupported': True,
@@ -113,7 +119,7 @@ def assume_role(account_id, role='AWSControlTowerExecution'):
113119

114120
else:
115121
config_recorder = {
116-
'name': 'aws-controltower-BaselineConfigRecorder',
122+
'name': recorder_name,
117123
'roleARN': role_arn,
118124
'recordingGroup': {
119125
'allSupported': False,

0 commit comments

Comments
 (0)