Moto: Connection error while testing get_function_policy() with mock_lambda

Created on 9 Oct 2017  路  18Comments  路  Source: spulec/moto

Try running get_function_policy() in moto/tests/test_awslambda/test_lambda.py.
Here is my traceback:

Traceback (most recent call last):
  File "moto_test.py", line 722, in <module>
    get_function_policy()
  File "/env/lib/python2.7/site-packages/moto/core/models.py", line 70, in wrapper
    result = func(*args, **kwargs)
  File "moto_test.py", line 708, in get_function_policy
    Qualifier='2'
  File "/env/lib/python2.7/site-packages/botocore/client.py", line 312, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/env/lib/python2.7/site-packages/botocore/client.py", line 588, in _make_api_call
    operation_model, request_dict)
  File "/env/lib/python2.7/site-packages/botocore/endpoint.py", line 141, in make_request
    return self._send_request(request_dict, operation_model)
  File "/env/lib/python2.7/site-packages/botocore/endpoint.py", line 170, in _send_request
    success_response, exception):
  File "/env/lib/python2.7/site-packages/botocore/endpoint.py", line 249, in _needs_retry
    caught_exception=caught_exception, request_dict=request_dict)
  File "/env/lib/python2.7/site-packages/botocore/hooks.py", line 227, in emit
    return self._emit(event_name, kwargs)
  File "/env/lib/python2.7/site-packages/botocore/hooks.py", line 210, in _emit
    response = handler(**kwargs)
  File "/env/lib/python2.7/site-packages/botocore/retryhandler.py", line 183, in __call__
    if self._checker(attempts, response, caught_exception):
  File "/env/lib/python2.7/site-packages/botocore/retryhandler.py", line 251, in __call__
    caught_exception)
  File "/env/lib/python2.7/site-packages/botocore/retryhandler.py", line 269, in _should_retry
    return self._checker(attempt_number, response, caught_exception)
  File "/env/lib/python2.7/site-packages/botocore/retryhandler.py", line 317, in __call__
    caught_exception)
  File "/env/lib/python2.7/site-packages/botocore/retryhandler.py", line 223, in __call__
    attempt_number, caught_exception)
  File "/env/lib/python2.7/site-packages/botocore/retryhandler.py", line 359, in _check_caught_exception
    raise caught_exception
requests.exceptions.ConnectionError: Connection refused: POST https://lambda.us-west-2.amazonaws.com/2015-03-31/functions/testFunction/policy?Qualifier=2

All 18 comments

@dbfr3qs or @thehesiod could one of you triage this?

Hi @leoybkim, could you please provide the version of moto you are using?

@dbfr3qs It's the latest version moto==1.1.21

tests pass in travis, and "moto_test.py" does not exist in moto from what I see so sounds like something custom.

Are you using this within your own tests or are you simply running the moto unit tests? I am unable to replicate.

As an aside, I don't think this has actually been released yet even though it has been merged into master. If "moto_test.py" is your own tests, unfortunately 1.1.21 of moto does not include the ability to set and get lambda function policies yet, even though it exists in master. You will need to wait for a new release from @JackDanger

@thehesiod @dbfr3qs I pasted moto_test.py and my python libs installed in my virtual environment into this gist. It's the exact same test_lambda.py from master branch with the main function calling get_function_policy().

Yes, but it is trying to call code from the master branch which doesn't exist in moto 1.1.21...

@dbfr3qs Ok, that answers my question. Thanks for the response!

seems like @dbfr3qs know's what's going on, what's odd is that per the exception it seems like it's trying to connect to https://lambda.us-west-2.amazonaws.com/2015-03-31/functions/testFunction/policy?Qualifier=2, but instead should be calling into moto. If it were not implemented I would hope a different type of exception would be thrown than requests.exceptions.ConnectionError: Connection refused

See this: https://github.com/spulec/moto/blob/1.1.21/moto/awslambda/urls.py - it does not even contain the regex required for the url lookup - which is in master: https://github.com/spulec/moto/blob/master/moto/awslambda/urls.py

@leoybkim No problem. Keep an eye out for the next release 馃憤

@thehesiod it would be a good idea to return a not implemented error, perhaps generic for when a url lookup does not exist?

@dbfr3qs ahh...thanks, now I get it, it does not rewrite the url so it tries to connect to the real endpoint. Just logged https://github.com/spulec/moto/issues/1254 so this will make more sense later :)

I've just realized the current master as Moto 1.1.22. Hopefully this clears up some confusion!

I'm wondering if this issue can be closed?

@dbfr3qs I'm okay with closing it as long as it is fixed in the next release

I believe that was fixed in the release mentioned above.

Was this page helpful?
0 / 5 - 0 ratings