import boto3def enable_global_resource_recording(): try: config = boto3.client('config') # Check if Configuration Recorders exist recorders = config.describe_configuration_recorders()['ConfigurationRecorders'] if not recorders: # Create a new Configuration Recorder config.put_configuration_recorder(ConfigurationRecorder={ 'name': 'default', 'recordingGroup': {'allSupported': True} }) print("Configuration Recorder created with global resource recording enabled.") else: for recorder in recorders: if not recorder.get('recordingGroup', {}).get('allSupported', False): # Update existing Configuration Recorder to enable global resource recording config.put_configuration_recorder(ConfigurationRecorder={ 'name': recorder['name'], 'recordingGroup': {'allSupported': True} }) print(f"Global resource recording enabled for Configuration Recorder: {recorder['name']}") break else: print("Global resource recording is already enabled for all Configuration Recorders.") except Exception as e: print(f"Error: {e}")# Execute remediationenable_global_resource_recording()
Ensure that you have the necessary permissions to update AWS Config settings using the AWS CLI or Python script. Also, review and test the changes before applying them to production environments.