why mock is failing and asking for aws credential to run locally?

Viewed 997

I am using below code for running test cases locally, but it is asking for aws credentials which I not supposed to give. Its like mock/moto is failing some how. as I am new to this to python and itss library, I am unable to understand it deeper

import sys, os
import pprint
myPath = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, myPath + '/../')
from botocore.exceptions import ClientError
pprint.pprint(sys.path)
import pytest
from services.testrun_result_details import *
import json
from moto import *
from mock import MagicMock, patch
import boto3

@mock_dynamodb2
@patch('boto3.resource')
def test_success_response(dynamodb_test_testrun_results):
    create_dynamodb_tables()
    response = run_result_details_handler(EVENT_JSON, None)
    assert response["statusCode"] == 200

---------------------------Error-------------------------

/usr/local/lib/python3.7/site-packages/botocore/signers.py:90: in handler
    return self.sign(operation_name, request)
/usr/local/lib/python3.7/site-packages/botocore/signers.py:162: in sign
    auth.add_auth(request)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = <botocore.auth.SigV4Auth object at 0x7fab7fc2ee50>
request = <botocore.awsrequest.AWSRequest object at 0x7fab7fc48d90>
    def add_auth(self, request):
        if self.credentials is None:
>           raise NoCredentialsError()
E           botocore.exceptions.NoCredentialsError: Unable to locate credentials
/usr/local/lib/python3.7/site-packages/botocore/auth.py:373: NoCredentialsError

can anyone suggest me, how to resolve that issue?

1 Answers

I found the issue to be that my ~/.aws/credentials file did not have a default profile.

I added this, which fixed the issue:

[default]
aws_access_key_id = 123
aws_secret_access_key = ABC
Related