moto: test_lambda.py:test_invoke_requestresponse_function test failing os x/linux since 1.1.20

Hi there, since moto 1.1.20 the above test has started to fail on my machine (OS X 10.11) and our Ubuntu 16.04 linux build agents, both Python 2.7 and 3.5. Any test that we have which uses invoke_lambda is now erroring out. There does not appear to be a clean version of moto I can pin to because of other changes that were made that were also included in this release that my tests rely on. Would it be possible to get this addressed ASAP?

I believe this is the commit which caused it:

https://github.com/spulec/moto/commit/9008b852995146b85296174108fc94c5f727bcb5#diff-2df06bdd95e3c78b9335da9f260a3472

Here is the stack trace:

~/D/W/moto (master↑3|…) $ nosetests tests/test_awslambda/test_lambda.py:test_invoke_requestresponse_function -s
Traceback (most recent call last):
  File "/Users/chris.keogh/Documents/Workspace/moto/moto/awslambda/models.py", line 291, in _invoke_lambda
    with _DockerDataVolumeContext(self) as data_vol:
  File "/Users/chris.keogh/Documents/Workspace/moto/moto/awslambda/models.py", line 94, in __enter__
    for vol in self._lambda_func.docker_client.volumes.list():
  File "/usr/local/lib/python2.7/site-packages/docker-2.5.1-py2.7.egg/docker/models/volumes.py", line 92, in list
    resp = self.client.api.volumes(**kwargs)
  File "/usr/local/lib/python2.7/site-packages/docker-2.5.1-py2.7.egg/docker/utils/decorators.py", line 34, in wrapper
    return f(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/docker-2.5.1-py2.7.egg/docker/api/volume.py", line 38, in volumes
    return self._result(self._get(url, params=params), True)
  File "/usr/local/lib/python2.7/site-packages/docker-2.5.1-py2.7.egg/docker/utils/decorators.py", line 46, in inner
    return f(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/docker-2.5.1-py2.7.egg/docker/api/client.py", line 189, in _get
    return self.get(url, **self._set_request_timeout(kwargs))
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 521, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/adapters.py", line 490, in send
    raise ConnectionError(err, request=request)
ConnectionError: ('Connection aborted.', error(61, 'Connection refused'))
E
======================================================================
ERROR: test_lambda.test_invoke_requestresponse_function
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/Users/chris.keogh/Documents/Workspace/moto/moto/core/models.py", line 70, in wrapper
    result = func(*args, **kwargs)
  File "/Users/chris.keogh/Documents/Workspace/moto/tests/test_awslambda/test_lambda.py", line 81, in test_invoke_requestresponse_function
    base64.b64decode(success_result["LogResult"]).decode('utf-8'))
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 24 (15 by maintainers)

Most upvoted comments

@thehesiod thanks for the tip on the lambda function name, that fixed my tests! You have no idea how grateful I am! 👍

@JackDanger I think that’s an excellent compromise. After working through it, I only had to make one small change which @thehesiod pointed out to get my tests to run again with Docker. I’m feeling a lot less negatively towards it, but I do think we need some clear documentation around it.

@JackDanger @thehesiod @terrycain thanks for your help. This is a great project, and I feel privileged to be involved.

ok, wrote up something quick here: http://hesiod.blogspot.com/2017/10/mocking-aws-lambdas.html

@dbfr3qs yes! I fixed that in my PR as well. See in my blogpost. When you create the function you can specify the environment variables it should be run with

@thehesiod If you were to write a blog post showing a simple case of how you use lambda in Moto that would be so, so useful to Python developers everywhere. Basically, nobody I know has any way to test their lambda code anywhere. This is a huge feature!

btw with some work the MotoService can be largely eliminated by incorporating a shutdown and/or reset endpoint to the moto.server…also adding a context class helper and wait for service to come up. Sorry, I could go on for ideas, so many features, so little time 😃

I’ll have to PR less ha 😉

So I’m guessing that won’t help in this case. Plus then I bet we’ll get a ton of bugs logged asking why lambda functionality is not available.

It may not help for this particular case but I recently realized how many different dependencies the docker library pulls in. For example, anybody using Moto in their application now has to bundle moto, docker, and websockets-client. For companies that need to audit all of the dependencies they use that’s asking a lot of our users. Having the default be to not support Lambda (and print a big, obvious warning banner if they try to @mock_lambda showing users what they need to do) and allowing folks to opt-in to Docker would be kinder, I think.