4

I am trying to deploy an AWS Lambda package. The language is Python 3.6, and it includes external modules (flask-ask and thereby indirectly cryptography). When I do so, and test the function, AWS reports error:

No module named 'cryptography.hazmat.bindings._openssl'

My development environment is Windows 10. My function works perfectly well on my development environment. I package the function up with Powershell script ...

& $pip install flask-ask -t $projectDir

... and then zip up the result and the function to make the zip package. My development version of Python 3.6 has 64-bit bitness.

Questions

Why does the function work locally, but not when packaged and sent to AWS? What is missing? and how do I fix it.

Similar questions

I've found other people had similar questions here:

I am loathe to switch to Python 2.7 . The second one only has solutions for a linux development environment.

3
  • Did you ever resolve this issue? I am unable to load Crypto native libraries when testing my lambda. Commented Apr 7, 2018 at 23:37
  • Chris, the resolution was to use Python Commented Apr 13, 2018 at 5:21
  • Can you clarify? Do you mean you reverted to Python 2.7? If so, how did you get around the other incompatibilities in the pyOpenSSL library and 2.7? Commented Jul 5, 2018 at 16:43

1 Answer 1

4

Late answer, but a key thing to understand in AWS Lambda development is that the run-time environment, independent of language, is a stripped down Amazon Linux container. Python code with native dependencies like cryptography makes use of OS- and architecture-specific binaries.

When you run pip install cryptography, it's working in the context of your local machine, which means that any dependent binaries will be installed according to the OS flavor and CPU architecture. You can't package those up and run them in the AWS Lambda environment.

The solution is to either use tools that assemble your dependencies from pre-packaged distributions (Zappa does this), or perform a build step that installs/compiles dependencies in a compatible environment (AWS SAM CLI does this).

I personally prefer the AWS SAM CLI, but YMMV.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.