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

KeyError: 'flaggedResources' #337

Closed
agassner opened this issue Mar 5, 2018 · 7 comments
Closed

KeyError: 'flaggedResources' #337

agassner opened this issue Mar 5, 2018 · 7 comments
Assignees
Labels

Comments

@agassner
Copy link

agassner commented Mar 5, 2018

KeyError: 'flaggedResources' when running on an account with Trusted Advisor and Business Support.

Version

$ awslimitchecker --version
awslimitchecker 4.0.0 is AGPL-licensed free software; all users have a right to the full source code of this version. See <https://github.com/jantman/awslimitchecker>
awslimitchecker 4.0.0 (see <https://github.com/jantman/awslimitchecker> for source code)

Installation Method

Using pyenv.
pip install awslimitchecker

Supporting Software Versions

$ python --version
Python 3.6.4

$ pyenv --version
pyenv 1.2.1

OS: Darwin Kernel Version 15.6.0: Tue Jan  9 20:12:05 PST 2018; root:xnu-3248.73.5~1/RELEASE_X86_64 x86_64

Code

import logging

from awslimitchecker.checker import AwsLimitChecker


FORMAT = '%(message)s'
logging.basicConfig(format=FORMAT)
logger = logging.getLogger('wrapper')
logger.setLevel(logging.INFO)


c = AwsLimitChecker(
    account_id='111111111111',
    account_role='myrole',
    region='sa-east-1'
)

result = c.check_thresholds()

Actual Output

$ python test.py
awslimitchecker 4.0.0 is AGPL-licensed free software; all users have a right to the full source code of this version. See <https://github.com/jantman/awslimitchecker>
Traceback (most recent call last):
  File "test.py", line 19, in <module>
    result = c.check_thresholds()
  File "/Users/agassner/.pyenv/versions/3.6.4/lib/python3.6/site-packages/awslimitchecker/checker.py", line 550, in check_thresholds
    self.ta.update_limits()
  File "/Users/agassner/.pyenv/versions/3.6.4/lib/python3.6/site-packages/awslimitchecker/trustedadvisor.py", line 141, in update_limits
    ta_results = self._poll()
  File "/Users/agassner/.pyenv/versions/3.6.4/lib/python3.6/site-packages/awslimitchecker/trustedadvisor.py", line 175, in _poll
    for check in checks['result']['flaggedResources']:
KeyError: 'flaggedResources'
@jantman jantman added the bug label Mar 5, 2018
@jantman
Copy link
Owner

jantman commented Mar 5, 2018

@agassner Hmm... this is a new one to me, I've never seen it before. My guess is that either it's some strange intermittent failure, or the Trusted Advisor API changed suddenly and they didn't tell anyone...

Since I know that I can't reproduce this in any of the accounts that I have access to, I'm going to work on a script that you can run to capture some better debugging information...

@jantman
Copy link
Owner

jantman commented Mar 5, 2018

@agassner Do you think that you could please run the script in this Gist in the same pyenv as awslimitchecker, and paste either the output or at least the last line ("CHECK RESULT:")?

@agassner
Copy link
Author

agassner commented Mar 5, 2018

@jantman sure, not a problem.

$ python awslimitchecker_issue_337.py
[2018-03-05 14:12:03,464 DEBUG] Loading variable profile from defaults.
[2018-03-05 14:12:03,464 DEBUG] Loading variable config_file from defaults.
[2018-03-05 14:12:03,468 DEBUG] Loading variable credentials_file from defaults.
[2018-03-05 14:12:03,468 DEBUG] Loading variable data_path from defaults.
[2018-03-05 14:12:03,468 DEBUG] Loading variable profile from defaults.
[2018-03-05 14:12:03,468 DEBUG] Loading variable ca_bundle from defaults.
[2018-03-05 14:12:03,468 DEBUG] Loading variable profile from defaults.
[2018-03-05 14:12:03,468 DEBUG] Loading variable api_versions from defaults.
[2018-03-05 14:12:03,468 DEBUG] Loading variable profile from defaults.
[2018-03-05 14:12:03,468 DEBUG] Loading variable credentials_file from defaults.
[2018-03-05 14:12:03,469 DEBUG] Loading variable config_file from defaults.
[2018-03-05 14:12:03,469 DEBUG] Loading variable profile from defaults.
[2018-03-05 14:12:03,469 DEBUG] Loading variable metadata_service_timeout from defaults.
[2018-03-05 14:12:03,469 DEBUG] Loading variable profile from defaults.
[2018-03-05 14:12:03,469 DEBUG] Loading variable metadata_service_num_attempts from defaults.
[2018-03-05 14:12:03,480 DEBUG] Loading variable profile from defaults.
[2018-03-05 14:12:03,480 DEBUG] Looking for credentials via: env
[2018-03-05 14:12:03,480 INFO] Found credentials in environment variables.
[2018-03-05 14:12:03,480 DEBUG] Loading JSON file: /Users/agassner/.pyenv/versions/3.6.4/lib/python3.6/site-packages/botocore/data/endpoints.json
[2018-03-05 14:12:03,484 DEBUG] Loading variable profile from defaults.
[2018-03-05 14:12:03,484 DEBUG] Event choose-service-name: calling handler <function handle_service_name_alias at 0x10b3a7268>
[2018-03-05 14:12:03,492 DEBUG] Loading JSON file: /Users/agassner/.pyenv/versions/3.6.4/lib/python3.6/site-packages/botocore/data/support/2013-04-15/service-2.json
[2018-03-05 14:12:03,494 DEBUG] Event creating-client-class.support: calling handler <function add_generate_presigned_url at 0x10b379b70>
[2018-03-05 14:12:03,494 DEBUG] The s3 config key is not a dictionary type, ignoring its value of: None
[2018-03-05 14:12:03,625 DEBUG] Setting support timeout as (60, 60)
[2018-03-05 14:12:03,625 DEBUG] Loading JSON file: /Users/agassner/.pyenv/versions/3.6.4/lib/python3.6/site-packages/botocore/data/_retry.json
[2018-03-05 14:12:03,626 DEBUG] Registering retry handlers for service: support
[2018-03-05 14:12:03,626 INFO] getting limit check ID...
[2018-03-05 14:12:05,148 DEBUG] Found TA check id=eW7HH0l7J9 - {'id': 'eW7HH0l7J9', 'name': 'Service Limits', 'description': 'Checks for usage that is more than 80% of the service limit. Values are based on a snapshot, so your current usage might differ. Limit and usage data can take up to 24 hours to reflect any changes. In some cases, your usage might be greater than the indicated limit for a period of time. <br>\n<b>Note</b>: For information about which service limits are checked, see <a href="https://aws.amazon.com/premiumsupport/ta-faqs/#service-limits-check-questions" target="_blank">Service Limits Check Questions</a><br/>\n<br>\n<b>Alert Criteria</b><br>\nYellow: Usage is more than 80% of the service limit.<br>\n<br>\n<b>Recommended Action</b><br>\nIf you anticipate exceeding a service limit, open a case in Support Center to <a href="https://aws.amazon.com/support/createCase?type=service_limit_increase" target="_blank">request a limit increase</a>.<br>\n<br>\n<b>Additional Resources</b><br>\n<a href="https://aws.amazon.com/premiumsupport/ta-faqs/" target="_blank">Trusted Advisor FAQs</a><br/>\n<a href="https://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html" target="_blank">AWS Service Limits</a><br/>\n<a href="https://console.aws.amazon.com/ec2/v2/home?#Limits:" target="_blank">EC2 Service Limits</a> (per region) in the Amazon EC2 console', 'category': 'performance', 'metadata': ['Region', 'Service', 'Limit Name', 'Limit Amount', 'Current Usage', 'Status']}
[2018-03-05 14:12:05,148 INFO] Getting check result for check eW7HH0l7J9
[2018-03-05 14:12:05,356 DEBUG] Got TrustedAdvisor data for check eW7HH0l7J9 but unable to parse timestamp
[2018-03-05 14:12:05,356 INFO] CHECK RESULT: {"result": {"checkId": "eW7HH0l7J9", "status": "not_available"}, "ResponseMetadata": {"RequestId": "2ecca915-207f-11e8-9f50-15f8fa362b6a", "HTTPStatusCode": 200, "HTTPHeaders": {"x-amzn-requestid": "2ecca915-207f-11e8-9f50-15f8fa362b6a", "content-type": "application/x-amz-json-1.1", "content-length": "60", "date": "Mon, 05 Mar 2018 14:12:05 GMT"}, "RetryAttempts": 0}}

@jantman
Copy link
Owner

jantman commented Mar 6, 2018

Hmm, that's very strange indeed. I've never seen that check with "status": "not_available" before, nor have I heard any other reports of that.

I'll do my best to get a fix for this out this afternoon/evening or tomorrow evening. In the mean time, if you don't need the Trusted Advisor data, you can run with the flag to disable Trusted Advisor.

@agassner
Copy link
Author

agassner commented Mar 6, 2018

Thanks @jantman

I have a quick fix for this on agassner@878a7c3#diff-90133b65e9bab3d9751e1ffc5ce1522aR175
It's a just a key exists check on the result.

I can send you a PR later if you want. I need to read the PR guidelines first :)

@jantman jantman added the ready label Mar 9, 2018
@jantman
Copy link
Owner

jantman commented Mar 9, 2018

@agassner Sorry for the delay on this. Thanks for all of the assistance. I should have a fix released today or tomorrow.

@jantman jantman self-assigned this Mar 9, 2018
@jantman jantman added in progress and removed ready labels Mar 9, 2018
jantman added a commit that referenced this issue Mar 9, 2018
fixes #337 - handle Trusted Advisor broken checks
@jantman
Copy link
Owner

jantman commented Mar 10, 2018

This has been released in 4.0.1 and is now live on PyPI.

nadlerjessie pushed a commit to nadlerjessie/awslimitchecker that referenced this issue Feb 16, 2019
… status not_available or missing flaggedResources key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants