Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vishal-yadav-safe opened this issue Mar 1, 2025 · 1 comment
Labels
bug Something isn't working documentation Improvements or additions to documentation

Comments

@vishal-yadav-safe
Copy link

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.

@vishal-yadav-safe vishal-yadav-safe added bug Something isn't working documentation Improvements or additions to documentation labels Mar 1, 2025
@vishal-yadav-safe
Copy link
Author

Raised a PR to fix this issue - #316

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant