1

I am trying to create a Python function for AWS Lambda that uses the passlib library for password hashing with argon2. To this end, I am using pip to install the following packages in a local directory, zipping them with my Python file, and uploading to Lambda:

passlib==1.7.1
argon2-cffi==18.1.0
cffi==1.11.5
pycparser==2.18
six==1.11.0

These packages are sufficient to let me use argon2 through passlib on my local Ubuntu environment. However, I keep getting the following error when testing in Lambda:

  File "/var/task/my-function.py", line 41, in handler
    if argon2.verify(password, hash):
  File "/var/task/passlib/handlers/argon2.py", line 525, in verify
    cls._stub_requires_backend()
  File "/var/task/passlib/utils/handlers.py", line 2221, in _stub_requires_backend
    cls.set_backend()
  File "/var/task/passlib/utils/handlers.py", line 2143, in set_backend
    raise default_error
passlib.exc.MissingBackendError: argon2: no backends available -- recommend you install one (e.g. 'pip install argon2_cffi')

In the Lambda console, it appears that everything is uploading as expected.

I would ideally like to know how to correctly package my Python application for Lambda, but would also accept other ways of doing argon2 or bcrypt password hashing and hash verification in Lambda. Thanks in advance for all help!

cwh
  • 63
  • 1
  • 9

1 Answers1

0

It turns out I wasn't including all of the required files when I was creating my .zip archive, as described here: https://stackoverflow.com/questions/38963857/import-error-from-cyptography-hazmat-bindings-constant-time-import-lib

In the process of debugging, I created an Amazon Linux environment to install/compile libraries for maximum Lambda compatibility. So my process for packaging Lambda functions now looks like this:

  1. Spin up an Amazon Linux environment (e.g. Docker).
  2. Use yum to install zip, libffi-devel, desired Python version (I used python36), and virtualenv.
  3. Create and activate a virtual environment. Install all Python packages with pip.
  4. Create a .zip archive including the Lambda function and all site packages from the virtual environment. For example:

    zip -9 lambda.zip myfunction.py
    cd venv/lib/python3.6/site-packages/
    zip -r9 ../../../../lambda.zip .
    cd ../../../lib64/python3.6/site-packages/
    zip -r9 ../../../../lambda.zip
    
  5. Upload lambda.zip to AWS Lambda.

cwh
  • 63
  • 1
  • 9