I started out pasting Python code into the AWS Lambda web GUI, right in that textarea. Got it working, making a call to a Slack API (whee!). So I had a working test case and I could test a refactor.
With the same code, I wanted to take advantage of the cool zipfile/ virtualenv upload support ("Create a Deployment Package") so I could use third-party libraries. Keeping the code itself the same (same as what I'd pasted into the textarea), the test should work again, as long as I packaged it right.
I kept trying to upload a zip with the same code, I thought, to AWS Lambda ... but I kept getting an error:
"module initialization error"
Or ...
module initialization error: 'NoneType' object has no attribute 'close'
I was banging my head against the wall a bit, with this.
I figured out my problem and it was just that I got screwed up with overloaded or vague terms. I was thinking at the wrong level of modularity.
In AWS I could see my configuration said to use this Handler:
lambda_function.lambda_handler
So I had a file structure like this:
└── lambda_function
├── __init__.py
└── lambda_handler.py
Both are wrong. lambda_function
in the default configuration for AWS Lambda refers to a module,
and lamdba_handler
refers to a function within the module. Seems obvious in retrospect,
but the names are vague, and if you're like me ... you're not used to putting module_name.function_name
in an HTML form and having stuff work.
Anyway, this is the file structure that ACTUALLY matches the default configuration:
lambda_function.py
And that's it. lambda_function.py
should have:
def lambda_handler(event, context):
# ...
So you can get that working, and then if you want, you can rename things from there.
Happy hacking :)
haha, yeah i have everything setup correctly and i still am stuck with lambda... i used github/kappa for a bit but its not usable for my case :/