jantman / awslimitchecker

A script and python package to check your AWS service limits and usage via boto3.
http://awslimitchecker.readthedocs.org/
GNU Affero General Public License v3.0
514 stars 188 forks source link

CloudTrail Service - API response missing "EventSelectors" results in unhandled KeyError #578

Open rehamkhalil3 opened 1 year ago

rehamkhalil3 commented 1 year ago

My lambda function using AWslimitchecker API was working for 1 year and half then yesterday while running the lambda function this error pop-out without changing any thing in codes or repository

Bug Report

"errorMessage": "'EventSelectors'", "errorType": "KeyError", from cloudtrail.py

Actual Output

"errorMessage": "'EventSelectors'", "errorType": "KeyError", from cloudtrail.py

Expected Output

getting all Aws services quotas limits if the usage exceeds the critical thresholds

kindly help why the cloudtrail cause that error and how to resolve it so the lambda function will work again

jantman commented 1 year ago

Please fill out everything in the issue template that you deleted:

Before opening an issue, please see the Getting Help page of the documentation.

Please remove all of this template but the relevant section below, and fill in each item in that section.

Bug Report

When reporting a bug in awslimitchecker, please provide all of the following information, as well as any additional details that may be useful in reproducing or fixing the issue:

Version

awslimitchecker version, as reported by awslimitchecker --version

Installation Method

How was awslimitchecker installed (provide as much detail as possible, ideally the exact command used and whether it was installed in a virtualenv or not).

Supporting Software Versions

The output of python --version and virtualenv --version in the environment that awslimitchecker is running in, as well as your operating system type and version.

Actual Output

Paste here the output of awslimitchecker (including the command used to run it),
run with the -vv (debug-level output) flag, that shows the issue.

Expected Output

Describe the output that you expected (what's wrong). If possible, after your description, copy the actual output above and modify it to what was expected.

TrustedAdvisor

If the bug/issue is related to TrustedAdvisor, which support contract your account has.

Testing Assistance

Indicate whether or not you will be able to assist in testing pre-release code for the feature.

rehamkhalil3 commented 1 year ago

Version awslimitchecker version, as reported by awslimitchecker --version (12.0.0)

Installation Method using Awslimitchecker API with terraform code to create the awslimitchecker tool lambda function [from awslimitchecker.checker import AwsLimitChecker]

Supporting Software Versions The output of python --version and virtualenv --version in the environment that awslimitchecker is running in, as well as your operating system type and version.

Actual Output when running the main.py this error pops-out [ thresholds = c.check_thresholds() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/awslimitchecker/checker.py", line 633, in check_thresholds tmp = cls.check_thresholds() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/awslimitchecker/services/base.py", line 281, in check_thresholds self.find_usage() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/awslimitchecker/services/cloudtrail.py", line 67, in find_usage self._find_usage_cloudtrail() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/awslimitchecker/services/cloudtrail.py", line 92, in _find_usage_cloudtrail event_selectors = response['EventSelectors'] KeyError: 'EventSelectors'

Process finished with exit code 1] Expected Output sending all critical and warning limit thresholds for Aws services that mentioned below in a config.json file- we are not monitoring all services just the ones that we are using also the issue with region us-west-2 that we are using the most

TrustedAdvisor no

Testing Assistance want to fix the bug - the lambda function was working fine for year and half then this error takes place and also the cloud trail service is not mentioned from the beginning in the config.file -we don't need to monitor this service and it's causing issues - i have tried now to add it to the config file and also still getting same issue for only region us-west-2 but the rest of regions are working fine

rehamkhalil3 commented 1 year ago

when i commented the line 92 in cloudtrail.py file it worked -so how to remove the line in my lambda because it can work localy but when i use my lambda function still taking the api from your repo and from cloudtrail.py

rehamkhalil3 commented 1 year ago

did you change anything regarding region:us-west-2 ?

rehamkhalil3 commented 1 year ago

after investigating by adding print statement to line 89 before the "EventSelectors"exception :

1.print(TrailName) the tool worked locally but still the lambda function using the global awslimitchecker api's which don't have the print statement 

jantman commented 1 year ago

Apologies for the delayed response.

I have not changed anything in awslimitchecker in a year and a half. This looks like AWS has changed their CloudTrail API responses.

As a workaround, if you don't need to monitor the CloudTrail service, there are instructions in the documentation for how to skip specific services when calling AwsLimitChecker via Python: https://awslimitchecker.readthedocs.io/en/latest/python_usage.html#skipping-specific-services

rehamkhalil3 commented 1 year ago

thank you so much by skipping the cloudtrail the lambda function worked again