Reputation: 123
I am trying to create a password protected zip file through lambda that is running on python 3.9
I have tried using pyminizip and pyzipper but i encounter error for both libraries
For pyminizip, I keep encountering
Unable to import module 'lambda_function': No module named 'pyminizip'
For pyzipper, I keep encountering
OSError: Cannot load native module 'Cryptodome.Hash._SHA1': Not found '_SHA1.cpython-39-x86_64-linux-gnu.so', Cannot load '_SHA1.abi3.so': /var/task/Cryptodome/Util/../Hash/_SHA1.abi3.so: invalid ELF header, Not found '_SHA1.so'
For the libraries, I tried attaching it as layer or zip it together with my deployment package as zip and I still encounter the same error as above.
May I know any one successfully managed to use python in lambda to password encrypted as zip file?
Thank you very much.
Upvotes: 0
Views: 1206
Reputation: 1874
You didn't post your code, your os, etc. Did you upload the lib and the so file with your code?
Since I don't know much about what you did, I have created a simple lambda using ubuntu, pyminizip and python 3.7 to test it.
First of all, install pyminizip in your project's folder:
pip install pyminizip -t .
Note that you'll see a new folder, and a new so file:
Note that you'll need to upload both to lambda.
Now, just write your code. I've created a simple script that reads a json I uploaded with my code, and save it zipped in lambda's tmp folder:
import os
import pyminizip
def lambda_handler(event, context):
print(os.path.exists("/tmp/test.zip"))
pyminizip.compress("test.json", None, "/tmp/test.zip", "awesomepassword", 9)
return "ok"
You can see the lambda's folder structure below:
And that's all. If you test your lambda, you'll see that it just works fine.
Upvotes: 1