gordon icon indicating copy to clipboard operation
gordon copied to clipboard

How to make use of common re-usable code with Gordon

Open JDFagan opened this issue 9 years ago • 3 comments

See attached images below. I'm trying to make use of a common sibling directory, "group" for my 3 different lambda functions: post, get, get_detail. I'm just testing post now just trying to get simple example of importing of sibling directory references in Python. Looking at build of post by Gordon, it appears its not sucking in the relative references that would be needed to be part of build to make this code work in AWS Lambda. Error I get by AWS is "module initialization error: Attempted relative import in non-package". You can see in the screenshot that I unzipped the group_post.zip file and its missing the relative reference as it seems that Gordon only builds out one directory that encapsulates the code.py lambda file.

group_post bad build top level settings yml

JDFagan avatar Jun 13 '16 19:06 JDFagan

Note, I did play with this and tried to create sample that makes use of common code but either Gordon doesn't yet support this or I'm attacking it wrong. My experience with common code across lambda functions within an app (microservice) is from Serverless. See https://serverlesscode.com/post/python-on-serverless-intro/ and look for section titled "Writing Common Code". I'm trying to achieve common lib code for an app (in my case model code for Pynamodb that would be re-usable across multiple lambda functions).

JDFagan avatar Jun 14 '16 05:06 JDFagan

👍

This would be useful as well as the ability to provide the pip dependencies in a zip file that can be merged into the deployment package. E.g. anything using PyOpenSSL needs to be compiled against openssl on an Amazon Linux AMI. Python modules with native C extensions compiled on OSX, err macOS, don't work when packaged up and deployed to lambda. By don't work I mean when executing the lambda function Python is unable to load the module containing the handler.

innonagle avatar Jul 15 '16 17:07 innonagle

@JDFagan Have you considered overriding the build option in settings.yaml? http://gordon.readthedocs.io/en/latest/lambdas.html#build

dotkas avatar Sep 19 '17 20:09 dotkas