Skip to content

Commit 2314fc8

Browse files
authored
Merge pull request #24 from chroju/fix_max_num_of_configuration_recorder_exceeded_exception
Use existing AWS Config recorder name to prevent recorder limit exception
2 parents d1555d7 + f5781a0 commit 2314fc8

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:
@@ -112,7 +118,7 @@ def assume_role(account_id, role='AWSControlTowerExecution'):
112118
if event == 'Delete':
113119
response = configservice.put_configuration_recorder(
114120
ConfigurationRecorder={
115-
'name': 'aws-controltower-BaselineConfigRecorder',
121+
'name': recorder_name,
116122
'roleARN': role_arn,
117123
'recordingGroup': {
118124
'allSupported': True,
@@ -123,7 +129,7 @@ def assume_role(account_id, role='AWSControlTowerExecution'):
123129

124130
else:
125131
config_recorder = {
126-
'name': 'aws-controltower-BaselineConfigRecorder',
132+
'name': recorder_name,
127133
'roleARN': role_arn,
128134
'recordingGroup': {
129135
'allSupported': False,

0 commit comments

Comments
 (0)