-
Notifications
You must be signed in to change notification settings - Fork 135
Description
Describe the bug
In AMAZON_EC2_AUDITOR, is failing with with exception: list index out of range.
This is happening in this code snippet :
try:
instanceLaunchedAt = i["BlockDeviceMappings"][0]["Ebs"]["AttachTime"]
except KeyError:
instanceLaunchedAt = i["LaunchTime"]
-
i["BlockDeviceMappings"] Might Be an Empty List
If an EC2 instance has no block device mappings, BlockDeviceMappings will be an empty list ([]).
Trying to access index 0 (BlockDeviceMappings[0]) when the list is empty will result in a list index out of range
error. -
Ebs Key Might Not Exist
Even if BlockDeviceMappings contains elements, there is no guarantee that the first entry
(BlockDeviceMappings[0]) has an "Ebs" key.
If it does not, trying to access ["Ebs"]["AttachTime"] will raise a KeyError
To Reproduce
Steps to reproduce the behavior:
Run EC2 auditor specifically , this error can be seen
Expected behavior
There should be proper handling of this to prevent such errors.
Screenshots
If applicable, add screenshots to help explain your problem.
Logs
Any stack traces, error reports, CloudTrail logs, etc.
Additional context
Add any other context about the problem here.