Skip to content

AMAZON_EC2_AUDITOR is failing with exception: list index out of range #315

@vishal-yadav-safe

Description

@vishal-yadav-safe

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"]
  1. 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.

  2. 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
Image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocumentationImprovements or additions to documentation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions