Miserlou / Zappa

Serverless Python
https://blog.zappa.io/
MIT License
11.89k stars 1.2k forks source link

NaCl ModuleNotFoundError. Issue deploying prebuilt wheel from Windows? #1033

Open tim-schier-frontier opened 7 years ago

tim-schier-frontier commented 7 years ago

Context

I'm using paramiko which uses PyNaCl. After deploying, I get an error log that finishes with:

  File "/var/task/paramiko/__init__.py", line 31, in <module>
  from paramiko.transport import SecurityOptions, Transport
  File "/var/task/paramiko/transport.py", line 57, in <module>
  from paramiko.ed25519key import Ed25519Key
  File "/var/task/paramiko/ed25519key.py", line 22, in <module>
  import nacl.signing
  File "/var/task/nacl/signing.py", line 19, in <module>
  import nacl.bindings
  File "/var/task/nacl/bindings/__init__.py", line 17, in <module>
  from nacl.bindings.crypto_box import (
  File "/var/task/nacl/bindings/crypto_box.py", line 18, in <module>
  from nacl._sodium import ffi, lib
ModuleNotFoundError: No module named 'nacl._sodium'

Looking in the zip file that was uploaded, I can see the a file nacl/_sodium.cp36-win_amd64.pyd, but not the Linux equivalent. If I download the manylinux wheel from PyPI, I see a file _sodium.cpython-36m-x86_64-linux-gnu.so in there.

So my question is how should I manage this - developing on a Windows machine but wanting Zappa to deploy to Lambda?

Steps to Reproduce

Set up development environment in Windows. In the virtual environment: pip install paramiko==2.2.1 In the Flask app file: import paramiko Run zappa deploy dev Access the web hook url. Run zappa tail to see the error.

Note if the import paramiko is removed then it works fine.

Your Environment

Windows 10 1703 64 bit Python 3.6.2 Zappa 0.43.1

zappa_settings.yml:

---
dev:

    # Basic setup.
    app_function: web_app.app
    s3_bucket: zappa-xxx
    runtime: "python3.6"

    # Manually manage the AWS IAM roles for increased security.
    # This should match the AWS IAM Lambda Execution role.
    manage_roles: false
    role_name: xxx

    # This should match the AWS credentials file.
    profile_name: zappa

    # Delete me, just for testing.
    delete_local_zip: false
    delete_s3_zip: false

    # We can't control where the code is stored, so don't store the auth credential files.
    # Code will automatically try credstash.
    exclude:
      - "*auth.ini"
      - "zappa_iam_policy.json"

    # Try and save more $ on execution.
    memory_size: 128

    debug: true

pip freeze output:

appdirs==1.4.3
argcomplete==1.8.2
asn1crypto==0.22.0
base58==0.2.4
bcrypt==3.1.3
boto==2.48.0
boto3==1.4.4
botocore==1.5.40
bz2file==0.98
cached-property==1.3.0
cachetools==2.0.0
certifi==2017.7.27.1
cffi==1.10.0
chardet==3.0.4
click==6.7
credstash==1.13.2
cryptography==1.9
defusedxml==0.5.0
docutils==0.14
durationpy==0.4
Flask==0.12.2
future==0.16.0
futures==3.1.1
google-api-python-client==1.6.2
hjson==2.0.7
httplib2==0.10.3
idna==2.5
isodate==0.5.4
itsdangerous==0.24
Jinja2==2.9.6
jmespath==0.9.3
kappa==0.6.0
lambda-packages==0.16.1
lxml==3.8.0
MarkupSafe==1.0
oauth2client==4.1.2
paramiko==2.2.1
phonenumbers==8.6.0
placebo==0.8.1
psycopg2==2.7.3
pyasn1==0.3.1
pyasn1-modules==0.0.10
pycparser==2.18
PyJWT==1.5.0
PyNaCl==1.1.2
PySocks==1.6.7
python-dateutil==2.6.1
python-slugify==1.2.4
pytz==2017.2
PyYAML==3.12
requests==2.18.3
requests-toolbelt==0.8.0
rsa==3.4.2
s3transfer==0.1.10
six==1.10.0
smart-open==1.5.3
SQLAlchemy==1.1.13
sshtunnel==0.1.2
toml==0.9.2
tqdm==4.14.0
troposphere==1.9.5
twilio==6.5.0
Unidecode==0.4.21
uritemplate==3.0.0
urllib3==1.22
Werkzeug==0.12.2
wsgi-request-logger==0.4.6
zappa==0.43.1
zeep==2.2.0
zenpy==1.2.2
tim-schier-frontier commented 7 years ago

I spun up a Docker container running Jessie, pulled my same code, installed the virtual environment and ran zappa update dev and it all works. Looking in the zip file, I can see nacl/_sodium.cpython-36m-x86_64-linux-gnu.so.