0

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.

1 Answer 1

1

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:

folder structure

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:

enter image description here

And that's all. If you test your lambda, you'll see that it just works fine.

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

2 Comments

Thank you so much for your respond, I am currently running python 3.9 as my lambda runtimes, but I still encounter the same error. Do look at my answer, where i upload more info on my deployment package
I had the same setup in my deployment package, yet I am still encountering the same problem for python 3.9 (i.sstatic.net/zFznu.png) Code used was this (i.sstatic.net/L6skg.png) , I have "import pyminizip" added at the top, completely clueless on what I am missing

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.