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

API calls for AWS is not being mocked even though moto is being used #2252

Closed
krtkvrm opened this issue Jun 18, 2019 · 1 comment
Closed

Comments

@krtkvrm
Copy link

krtkvrm commented Jun 18, 2019

I have referred #1926, #1793 and #2118 before opening this issue.

I am getting the error for ecr:

botocore.exceptions.ClientError: An error occurred (UnrecognizedClientException) when calling the DescribeRepositories operation: The security token included in the request is invalid.

and, I am also getting:

/home/x/proj/lib/python3.6/site-packages/requests/__init__.py:80: RequestsDependencyWarning: urllib3 (1.23) or chardet (3.0.4) doesn't match a supported version!
  RequestsDependencyWarning)
Performing system checks...

I am getting this error only when I add moto to requirements.txt
If I run pip install moto after running pip install -r requirements.txt, I am not getting both of the errors.
boto3==1.9.88
botocore==1.12.0
moto==1.3.8

It is accessing aws apis are when I disconnected, I got this:

Exception Value: Could not connect to the endpoint URL: "https://ecr.us-east-1.amazonaws.com/"

Code:

@if_non_prod_aws_mocker(mock_ecr)
@if_non_prod_aws_mocker(mock_sts)
def get_aws_credentials_for_submission(challenge, participant_team):
    repository, created = get_or_create_ecr_repository(
        ecr_repository_name, aws_keys
    )
    # getting error on line above
    #other codes

get_or_create_ecr_repository():

def get_or_create_ecr_repository(name, aws_keys):
    repository, created = None, False
    client = get_boto3_client("ecr", aws_keys)
    try:
        response = client.describe_repositories(
            registryId=aws_keys.get("AWS_ACCOUNT_ID"), repositoryNames=[name]  # Error is pointing at this line
        )
        repository = response["repositories"][0]
    except ClientError as e:
        if e.response["Error"]["Code"] == "RepositoryNotFoundException" or\
           e.response["Error"]["Code"] == "400":
            response = client.create_repository(repositoryName=name)
            repository = response["repository"]
            created = True
        else:
            logger.exception(e)
    return (repository, created)

@if_non_prod_aws_mocker:

def if_non_prod_aws_mocker(mocker):
    def decorator(func):
        if not (settings.DEBUG or settings.TEST):
            return func
        return mocker(func)
    return decorator
@krtkvrm
Copy link
Author

krtkvrm commented Jun 18, 2019

Updated botocore and moto using:

botocore==1.12.85
git+https://github.com/spulec/moto.git@df493ea18de22b4533073eee3e296686019911c2 # installing via commit till moto>1.3.8

@krtkvrm krtkvrm closed this as completed Jun 18, 2019
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

No branches or pull requests

1 participant