SimonH SimonH - 1 month ago 26
Python Question

Python 2.7 & emulambda

Just installed emulambda today, using the command:

pip install git+https://github.com/fugue/emulambda.git


and created a simple python file test.py:

from __future__ import print_function

def lambda_handler(event, context):
print("Hello world")


when I try and run this with the command

emulambda test.lambda_handler test-event.json


I get the errors

Oops! There was a problem finding your function.

Traceback (most recent call last):
File "/usr/local/bin/emulambda", line 5, in <module>
emulambda.main()
File "/usr/local/lib/python2.7/dist-packages/emulambda/__init__.py", line 37, in main
lfunc = import_lambda(args.lambdapath)
File "/usr/local/lib/python2.7/dist-packages/emulambda/__init__.py", line 121, in import_lambda
raise e
AttributeError: 'module' object has no attribute 'lambda_handler'


I'm running python 2.7.12 - can anyone suggest what the problem is?

Answer

You called your module test.py, which is a conflict with the internal Python regression test module when you attempt to do the following:

emulambda test.lambda_handler test-event.json

Rename your file to something else like simon_test.py and try it again with:

emulambda simon_test.lambda_handler test-event.json