Skip to content

Commit 1a0f995

Browse files
author
Avik
committed
Add exception handling for InternalServerException in lookup_associated_accounts
- Add exception handling for InternalServerException in lookup_associated_accounts - AWS Inspector sometimes returns InternalServerException instead of ResourceNotFoundException - Check error message for 'is not an associated member' to handle this case - Fixes issue #316 where account association checks would fail unexpectedly
1 parent 3b1e1e0 commit 1a0f995

File tree

1 file changed

+8
-0
lines changed
  • aws_sra_examples/solutions/inspector/inspector_org/lambda/src

1 file changed

+8
-0
lines changed

aws_sra_examples/solutions/inspector/inspector_org/lambda/src/inspector.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ def lookup_associated_accounts(inspector2_client: Inspector2Client, account_id:
131131
response = inspector2_client.get_member(accountId=account_id)
132132
except inspector2_client.exceptions.ResourceNotFoundException:
133133
return False
134+
except inspector2_client.exceptions.InternalServerException as e:
135+
# Check if this is the specific error about account not being associated
136+
if "is not an associated member" in str(e):
137+
LOGGER.info(f"Account {account_id} is not an associated member yet")
138+
return False
139+
else:
140+
LOGGER.error(f"Failed to get inspector members due to InternalServerException. {e}")
141+
raise
134142
except Exception as e:
135143
LOGGER.error(f"Failed to get inspector members. {e}")
136144
raise

0 commit comments

Comments
 (0)