question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

credentials mocking

See original GitHub issue

This is either a question or a request.

I’ve been unable to find any references to credentials profiles in the code, so I’m guessing these aren’t implemented yet.

I’m using different profiles for different groups, and I need to make my s3 connection using profile (i.e., aws_session = boto3.Session(profile_name=profile_name)

moto does not appear to mock the profile name; it must exist in the developers ~/.aws/credentials (or config).

Any chance this can be implemented and that other folks need it?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
dan-coatescommented, Oct 30, 2018

I think I’ve come across this same issue and have a relatively easy way to reproduce it. Essentially, if the AWS_PROFILE environment variable is set but the profile isn’t found in ~/.aws/config, it raises an exception on import:

________________________________________ ERROR collecting tests/test_create_cluster.py _________________________________________
tests/test_create_cluster.py:2: in <module>
    from moto import mock_s3
venv/lib/python3.6/site-packages/moto/__init__.py:9: in <module>
    from .apigateway import mock_apigateway, mock_apigateway_deprecated  # flake8: noqa
venv/lib/python3.6/site-packages/moto/apigateway/__init__.py:2: in <module>
    from .models import apigateway_backends
venv/lib/python3.6/site-packages/moto/apigateway/models.py:648: in <module>
    for region_name in Session().get_available_regions('apigateway'):
venv/lib/python3.6/site-packages/boto3/session.py:80: in __init__
    self._setup_loader()
venv/lib/python3.6/site-packages/boto3/session.py:120: in _setup_loader
    self._loader = self._session.get_component('data_loader')
venv/lib/python3.6/site-packages/botocore/session.py:729: in get_component
    return self._components.get_component(name)
venv/lib/python3.6/site-packages/botocore/session.py:946: in get_component
    self._components[name] = factory()
venv/lib/python3.6/site-packages/botocore/session.py:186: in <lambda>
    lambda:  create_loader(self.get_config_variable('data_path')))
venv/lib/python3.6/site-packages/botocore/session.py:281: in get_config_variable
    elif self._found_in_config_file(methods, var_config):
venv/lib/python3.6/site-packages/botocore/session.py:308: in _found_in_config_file
    return var_config[0] in self.get_scoped_config()
venv/lib/python3.6/site-packages/botocore/session.py:385: in get_scoped_config
    raise ProfileNotFound(profile=profile_name)
E   botocore.exceptions.ProfileNotFound: The config profile (~~~my-aws-profile-name~~~) could not be found

If I unset AWS_PROFILE, it’s totally fine with there being no ~/.aws/config at all. Since it’s fine if config doesn’t exist, it makes me think that it should tolerate a specific profile not being there.

1reaction
droratacommented, Nov 7, 2018

I suspect I’m witnessing a related, but different, issue. When I run the tests locally everything is fine (and I have the AWS credentials in ~/.aws). Once I try to run the tests within a docker container (which doesn’t contain the credentials) I get the following error:

botocore.exceptions.NoCredentialsError: Unable to locate credentials

This is thrown right after appearances of:

s3_conn = boto3.client('s3', 'us-west-2')
s3_conn.create_bucket(Bucket='test-bucket')

If, when I start the container, I mount my credentials the tests all pass. Furthermore, creating a dummy ~/.aws/credentials with the values:

[default]
aws_access_key_id = fOo
aws_secret_access_key = bAr

is enough and the tests passes.

NB: I’m not sure if it is related, but I have update some dependencies:

-moto==1.3.6
-boto3==1.7.84
-botocore==1.10.84
+moto==1.3.7
+boto3==1.9.38
+botocore>=1.12.13

This might be related.

Read more comments on GitHub >

github_iconTop Results From Across the Web

why mock is failing and asking for aws credential to run locally?
I am using below code for running test cases locally, but it is asking for aws credentials which I not supposed to give....
Read more >
Using AWS Mock Credentials for your unit tests in Travis
This allows you to run mock credentials for key AWS functionalities, let's see how we can set this up in Travis.
Read more >
Advanced workflows - Mocking and testing - AWS Amplify Docs
Learn how to quickly test and debug without pushing all changes in your Amplify project to the cloud. Use local mocking and testing...
Read more >
How To Mock AWS Services in Python Unit Tests
We're going to explore the moto library to mock AWS resources. ... Here, we're going to define fixtures to configure S3 mocking and...
Read more >
Running a Test as a User in Spring MVC Test
@Test @WithMockUser(roles = ["ADMIN"]) fun requestProtectedUrlWithUser() { mvc .get("/") // ... } Copied! Security RequestPostProcessors Mocking CSRF.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found