@@ -188,9 +188,6 @@ def get_all_organization_accounts(exclude_account_id: str = "111"):
188188 account_record = {"AccountId" : acct ["Id" ], "Email" : acct ["Email" ]}
189189 accounts .append (account_record )
190190 account_ids .append (acct ["Id" ])
191- except ClientError as ce :
192- logger .error (f"get_all_organization_accounts error: { ce } " )
193- raise ValueError ("Error getting accounts" )
194191 except Exception as exc :
195192 logger .error (f"get_all_organization_accounts error: { exc } " )
196193 raise ValueError ("Unexpected error getting accounts" )
@@ -319,8 +316,8 @@ def macie_create_members(service_client, accounts: list):
319316 }
320317 )
321318 time .sleep (1 ) # Sleeping 1 second to avoid max API call error
322- except Exception as exc :
323- logger .error (f"{ exc } " )
319+ except Exception as error :
320+ logger .error (f"{ error } " )
324321
325322
326323def configure_macie (session , delegated_account_id : str , available_regions : list , s3_bucket_name : str ,
@@ -358,13 +355,13 @@ def configure_macie(session, delegated_account_id: str, available_regions: list,
358355 )
359356
360357 # Create members for existing Organization accounts
361- logger .info (f"Existing Accounts: { accounts } " )
358+ logger .debug (f"Existing Accounts: { accounts } " )
362359 macie_create_members (regional_client , accounts )
363360
364361 # Update Organization configuration to automatically enable new accounts
365362 regional_client .update_organization_configuration (autoEnable = True )
366363 except Exception as exc :
367- logger .error (f"configure_macie Exception: { exc } " )
364+ logger .error (f"configure_macie in { region } Exception: { exc } " )
368365 raise ValueError (f"API Exception. Review logs for details." )
369366
370367
@@ -407,19 +404,19 @@ def disable_macie(macie2_client, account_id: str, region: str):
407404 response = macie2_client .get_administrator_account ()
408405 admin_account_id = response ["administrator" ]["accountId" ]
409406 except macie2_client .exceptions .ResourceNotFoundException :
410- logger .info (f"No delegated Macie administrator in { account_id } { region } " )
407+ logger .debug (f"No delegated Macie administrator in { account_id } { region } " )
411408
412409 try :
413410 if admin_account_id :
414411 logger .error (f"Administrator account is enabled within { account_id } { region } " )
415412 else :
416- logger .info (f"Disabling Macie in { account_id } { region } " )
413+ logger .debug (f"Disabling Macie in { account_id } { region } " )
417414 macie2_client .disable_macie ()
418415 except Exception as error :
419416 logger .error (f"Exception: { error } " )
420417 raise ValueError (f"Disable Macie Exception. See logs for error." )
421418 except macie2_client .exceptions .AccessDeniedException :
422- logger .info (f"Macie is not enabled within { account_id } { region } " )
419+ logger .debug (f"Macie is not enabled within { account_id } { region } " )
423420
424421
425422def delete_service_linked_role (session , role_name : str ):
@@ -454,7 +451,7 @@ def cleanup_member_account(session, account_id: str, available_regions: list):
454451 if session_macie :
455452 disable_macie (session_macie , account_id , region )
456453 except session_macie .exceptions .AccessDeniedException :
457- logger .info (f"Macie is not enabled in { account_id } { region } " )
454+ logger .debug (f"Macie is not enabled in { account_id } { region } " )
458455 except Exception as exc :
459456 logger .error (f"Error disabling Macie in { account_id } { region } Exception: { exc } " )
460457 raise ValueError (f"Error disabling Macie in { account_id } { region } " )
0 commit comments