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

Delete AWS_PROFILE, so that boto doesn't try and use it #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gergnz
Copy link

@gergnz gergnz commented Oct 5, 2017

Had an issue that produced the following stack trace:

raceback (most recent call last):
  File "/usr/local/bin/aws-mfa", line 337, in <module>
    main()
  File "/usr/local/bin/aws-mfa", line 86, in main
    validate(args, config)
  File "/usr/local/bin/aws-mfa", line 235, in validate
    get_credentials(short_term_name, key_id, access_key, args, config)
  File "/usr/local/bin/aws-mfa", line 257, in get_credentials
    aws_secret_access_key=lt_access_key
  File "/Library/Python/2.7/site-packages/boto3-1.4.4-py2.7.egg/boto3/__init__.py", line 83, in client
    return _get_default_session().client(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/boto3-1.4.4-py2.7.egg/boto3/__init__.py", line 72, in _get_default_session
    setup_default_session()
  File "/Library/Python/2.7/site-packages/boto3-1.4.4-py2.7.egg/boto3/__init__.py", line 34, in setup_default_session
    DEFAULT_SESSION = Session(**kwargs)
  File "/Library/Python/2.7/site-packages/boto3-1.4.4-py2.7.egg/boto3/session.py", line 80, in __init__
    self._setup_loader()
  File "/Library/Python/2.7/site-packages/boto3-1.4.4-py2.7.egg/boto3/session.py", line 120, in _setup_loader
    self._loader = self._session.get_component('data_loader')
  File "/Library/Python/2.7/site-packages/botocore-1.5.6-py2.7.egg/botocore/session.py", line 701, in get_component
    return self._components.get_component(name)
  File "/Library/Python/2.7/site-packages/botocore-1.5.6-py2.7.egg/botocore/session.py", line 897, in get_component
    self._components[name] = factory()
  File "/Library/Python/2.7/site-packages/botocore-1.5.6-py2.7.egg/botocore/session.py", line 181, in <lambda>
    lambda:  create_loader(self.get_config_variable('data_path')))
  File "/Library/Python/2.7/site-packages/botocore-1.5.6-py2.7.egg/botocore/session.py", line 265, in get_config_variable
    elif self._found_in_config_file(methods, var_config):
  File "/Library/Python/2.7/site-packages/botocore-1.5.6-py2.7.egg/botocore/session.py", line 286, in _found_in_config_file
    return var_config[0] in self.get_scoped_config()
  File "/Library/Python/2.7/site-packages/botocore-1.5.6-py2.7.egg/botocore/session.py", line 358, in get_scoped_config
    raise ProfileNotFound(profile=profile_name)
botocore.exceptions.ProfileNotFound: The config profile (ptml) could not be found

I could work around it by creating an empty section inside ~/.aws/credentials. This is possibly a bug in boto3, but this PR provides a cleaner workaround.

@broamski
Copy link
Owner

Can you please provide some more context around how you get this error? e.g. How your configs are setup, etc. I am unable to reproduce this. The latest version should gracefully handle this. Please let me know. Thanks

@gergnz
Copy link
Author

gergnz commented Dec 24, 2017

Hi @broamski,

This is still an issue:

environment setup:

export AWS_PROFILE=s2s-testing
export MFA_DEVICE="arn:aws:iam::123456789012:mfa/testing"

Then I just run aws-mfa:

INFO - Validating credentials for profile: s2s-testing
INFO - Short term credentials section s2s-testing is missing, obtaining new credentials.
Enter AWS MFA code for device [arn:aws:iam::123456789012:mfa/testing] (renewing for 43200 seconds):123456
Traceback (most recent call last):
  File "/usr/local/bin/aws-mfa", line 348, in <module>
    main()
  File "/usr/local/bin/aws-mfa", line 88, in main
    validate(args, config)
  File "/usr/local/bin/aws-mfa", line 242, in validate
    get_credentials(short_term_name, key_id, access_key, args, config)
  File "/usr/local/bin/aws-mfa", line 264, in get_credentials
    aws_secret_access_key=lt_access_key
  File "/Library/Python/2.7/site-packages/boto3/__init__.py", line 83, in client
    return _get_default_session().client(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/boto3/__init__.py", line 72, in _get_default_session
    setup_default_session()
  File "/Library/Python/2.7/site-packages/boto3/__init__.py", line 34, in setup_default_session
    DEFAULT_SESSION = Session(**kwargs)
  File "/Library/Python/2.7/site-packages/boto3/session.py", line 80, in __init__
    self._setup_loader()
  File "/Library/Python/2.7/site-packages/boto3/session.py", line 120, in _setup_loader
    self._loader = self._session.get_component('data_loader')
  File "/Library/Python/2.7/site-packages/botocore/session.py", line 726, in get_component
    return self._components.get_component(name)
  File "/Library/Python/2.7/site-packages/botocore/session.py", line 922, in get_component
    self._components[name] = factory()
  File "/Library/Python/2.7/site-packages/botocore/session.py", line 184, in <lambda>
    lambda:  create_loader(self.get_config_variable('data_path')))
  File "/Library/Python/2.7/site-packages/botocore/session.py", line 279, in get_config_variable
    elif self._found_in_config_file(methods, var_config):
  File "/Library/Python/2.7/site-packages/botocore/session.py", line 306, in _found_in_config_file
    return var_config[0] in self.get_scoped_config()
  File "/Library/Python/2.7/site-packages/botocore/session.py", line 383, in get_scoped_config
    raise ProfileNotFound(profile=profile_name)
botocore.exceptions.ProfileNotFound: The config profile (s2s-testing) could not be found

This was after doing a pip install -U aws-mfa.

Patched with my patch from above, and the issues is resolved.

Further info:

Mac OSX El Capitan
System python (2.7.10)
aws-mfa (0.0.10) [from pip list]

@broamski
Copy link
Owner

I'd like to get more insight so we can potentially properly handle this exception. A few questions:

  1. What are the contents of your ~/.aws/config file?

  2. Does your credentials file have a section for s2s-testing?

  3. Can you please provide the version of boto3 you are using via pip show boto3 | grep Version?

Thanks!

@gergnz
Copy link
Author

gergnz commented Jan 7, 2018

  1. ~/.aws/config
[default]
region = ap-southeast-2
output = json
s3 =
    signature_version = s3v4
[preview]
cloudfront = true
[s2s-testing]
output = text
region = us-west-2
[s2s-testing-dev]
role_arn=arn:aws:iam::123456789012:role/system/development
source_profile=s2s-testing
output = text
region = ap-southeast-2

I have many, many profiles that set different default regions/outputs and roles.

  1. No (not initially)

  2. Version: 1.5.6

Hope that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants