Issue while building python code in lambda
shivgit87 opened this issue ยท 2 comments
I have built JKS package and trying to execute the code in Lambda by uploading as a zip. While trying to test the code I am getting following error ๐
START RequestId: d210481c-b1d6-11e8-96b2-dbaf32b85648 Version: $LATEST
module initialization error: Cannot load native module 'Crypto.Hash._MD5': Trying '_MD5.cpython-36m-x86_64-linux-gnu.so': /var/task/Crypto/Util/../Hash/_MD5.cpython-36m-x86_64-linux-gnu.so: cannot open shared object file: No such file or directory, Trying '_MD5.abi3.so': /var/task/Crypto/Util/../Hash/_MD5.abi3.so: cannot open shared object file: No such file or directory, Trying '_MD5.so': /var/task/Crypto/Util/../Hash/_MD5.so: cannot open shared object file: No such file or directory
END RequestId: d210481c-b1d6-11e8-96b2-dbaf32b85648
REPORT RequestId: d210481c-b1d6-11e8-96b2-dbaf32b85648 Duration: 516.12 ms Billed Duration: 600 ms Memory Size: 128 MB Max Memory Used: 29 MB
module initialization error
Cannot load native module 'Crypto.Hash._MD5': Trying '_MD5.cpython-36m-x86_64-linux-gnu.so': /var/task/Crypto/Util/../Hash/_MD5.cpython-36m-x86_64-linux-gnu.so: cannot open shared object file: No such file or directory, Trying '_MD5.abi3.so': /var/task/Crypto/Util/../Hash/_MD5.abi3.so: cannot open shared object file: No such file or directory, Trying '_MD5.so': /var/task/Crypto/Util/../Hash/_MD5.so: cannot open shared object file: No such file or directory
It says Cannot load native module.
Hmm, seems like a packaging issue that's affecting the Crypto package (we use pycryptodome). Are other binary dependencies working?
I'm not familiar with Lambda's packaging requirements, but you may want to post in the appropriate support forums or on StackOverflow.
Came across this same issue. You need to install the runtime on linux system as cryptodome is os specific and lambda runs with linux backend
source - Legrandin/pycryptodome#69
Steps I followed
- spun up ec2 instance with amzn linux 2
- installed python3.8 -> https://techviewleo.com/how-to-install-python-on-amazon-linux/
- created own requirement file w/ updated pycryptodomex
pyasn1==0.3.5 pyasn1_modules==0.0.8 javaobj-py3==0.2.1 pycryptodomex==3.10.1
- ran requirements file
python3.8 -m pip install -r ./requirements.txt -t renew_certificate/ --no-dependencies
- zipped file, scp'd to my machine, uploaded to lambda
- need to create a lambda layer as the function is now too big to get the gui view
- need to change file structure so files are in python folder
python3.8 -m pip install -r requirements2.txt -t python --no-dependencies
- zip -r renew_certificate.zip python
- upload to lambda layer and set lambda layer in my lambda function