lambda-packages icon indicating copy to clipboard operation
lambda-packages copied to clipboard

No module named pyasn1.codec.der

Open FrancescoRizzi opened this issue 8 years ago • 2 comments

Hello. So, I've been trying to include one of the libs from lambda-packages, and failed repeatedly :(

I'm hitting on the error in the title:

No module named pyasn1.codec.der

Specifically, I'm trying to get the cryptography module into my lambda deployment packages, but maybe I'm misunderstanding the quick guide:

But, if you want to use this project the other (wrong) way, just put the contents of the .tar.gz archive into your lambda .zip.

Yes, I'm sorry, but I can't jump on Zappa at this point (maybe after this proof of concept is done), but it seems like I shouldn't have to, right?

So.. working on a Mac, I:

  • downloaded lambda-packages-master.zip, extracted its contents
  • dug into \lambda_packages\cryptography,
  • grabbed and extracted (to libs-for-aws\cryptography ) the cryptography-1.4.tar.gz archive.

Then I built my Lambda Deployment Package, and added to it the libs-for-aws\cryptography directory.

Package via Cloud Formation, deploy to AWS, and, when my Lambda is triggered, I get a 500, and in CloudWatch logs I get this message (cauth is just the name of my Lambda package)

START RequestId: 938e62f0-18a2-11e7-a55f-d146b6ce0af9 Version: $LATEST Unable to import module 'cauth': No module named pyasn1.codec.der END RequestId: 938e62f0-18a2-11e7-a55f-d146b6ce0af9

Am I doing something wrong in the way I'm trying to include the cryptography package from lambda-packages?

FrancescoRizzi avatar Apr 03 '17 19:04 FrancescoRizzi

Here are the steps to reproduce this problem

  1. Create this test zappa app.py
from flask import Flask
from cryptography.fernet import Fernet

app = Flask(__name__)

@app.route("/")
def hello():
    key = Fernet.generate_key()
    f = Fernet(key)
    token = f.encrypt(b"Hello World")
    return f.decrypt(token)

if __name__ == "__main__":
    app.run()
  1. Create this requirements.txt
flask
cryptography
git+https://github.com/Miserlou/Zappa.git
  1. Create the virtualenv and activate it
  2. pip install -r requirements.txt
  3. zappa init
  4. zappa deploy dev
  5. Browse to the new app URL

Expected results

Hello World

Actual results

500 error and in the logs

[1495734916232] [DEBUG] 2017-05-25T17:55:16.232Z 4e518819-4173-11e7-a448-3f29b99b1563 Zappa Event: {u'body': None, u'resource': u'/', u'requestContext': {u'resourceId': u'picembjsd2', u'apiId': u'wwp0dgegk6', u'resourcePath': u'/', u'httpMethod': u'GET', u'requestId': u'4e4c57fe-4173-11e7-a338-c9daeb2f8145', u'path': u'/dev', u'accountId': u'0123456789012', u'identity': {u'apiKey': u'', u'userArn': None, u'cognitoAuthenticationType': None, u'accessKey': None, u'caller': None, u'userAgent': u'python-requests/2.14.2', u'user': None, u'cognitoIdentityPoolId': None, u'cognitoIdentityId': None, u'cognitoAuthenticationProvider': None, u'sourceIp': u'1.2.3.4', u'accountId': None}, u'stage': u'dev'}, u'queryStringParameters': None, u'httpMethod': u'GET', u'pathParameters': None, u'headers': {u'Via': u'1.1 88972e3933cc06dd11a6fa704a208631.cloudfront.net (CloudFront)', u'Accept-Encoding': u'gzip, deflate', u'CloudFront-Is-SmartTV-Viewer': u'false', u'CloudFront-Forwarded-Proto': u'https', u'X-Forwarded-For': u'1.2.3.4, 2.3.4.5', u'CloudFront-Viewer-Country': u'US', u'Accept': u'*/*', u'User-Agent': u'python-requests/2.14.2', u'X-Amzn-Trace-Id': u'Root=1-59271a82-7613e79319606d9f4834ba54', u'Host': u'xxxxxxxxxx.execute-api.us-west-2.amazonaws.com', u'X-Forwarded-Proto': u'https', u'X-Amz-Cf-Id': u'sLxxxxxxxxxxxxxxxxxxxxxxxxxTuoY-HiBasUT72IxusLvw==', u'CloudFront-Is-Tablet-Viewer': u'false', u'X-Forwarded-Port': u'443', u'CloudFront-Is-Mobile-Viewer': u'false', u'CloudFront-Is-Desktop-Viewer': u'true'}, u'stageVariables': None, u'path': u'/', u'isBase64Encoded': False}
[1495734916365] [2017-05-25 17:55:16,365] ERROR in app: Exception on / [GET]
[1495734916365] Traceback (most recent call last):
[1495734916365] File "/tmp/pip-build-JnADOx/flask/flask/app.py", line 1982, in wsgi_app
[1495734916365] File "/tmp/pip-build-JnADOx/flask/flask/app.py", line 1614, in full_dispatch_request
[1495734916365] File "/tmp/pip-build-JnADOx/flask/flask/app.py", line 1517, in handle_user_exception
[1495734916365] File "/tmp/pip-build-JnADOx/flask/flask/app.py", line 1612, in full_dispatch_request
[1495734916365] File "/tmp/pip-build-JnADOx/flask/flask/app.py", line 1598, in dispatch_request
[1495734916365] File "/var/task/app.py", line 9, in hello
[1495734916365] f = Fernet(key)
[1495734916365] File "/tmp/tmpj9r4ps/lib64/python/cryptography/fernet.py", line 32, in __init__
[1495734916365] File "/tmp/tmpj9r4ps/lib64/python/cryptography/hazmat/backends/__init__.py", line 35, in default_backend
[1495734916365] File "/tmp/tmpj9r4ps/lib64/python/cryptography/hazmat/backends/__init__.py", line 22, in _available_backends
[1495734916365] File "/var/task/pkg_resources/__init__.py", line 2308, in resolve
[1495734916365] module = __import__(self.module_name, fromlist=['__name__'], level=0)
[1495734916365] File "/tmp/tmpj9r4ps/lib64/python/cryptography/hazmat/backends/openssl/__init__.py", line 7, in <module>
[1495734916365] File "/tmp/tmpj9r4ps/lib64/python/cryptography/hazmat/backends/openssl/backend.py", line 15, in <module>
[1495734916365] File "/tmp/tmpj9r4ps/lib64/python/cryptography/x509/__init__.py", line 7, in <module>
[1495734916365] File "/tmp/tmpj9r4ps/lib64/python/cryptography/x509/base.py", line 15, in <module>
[1495734916365] File "/tmp/tmpj9r4ps/lib64/python/cryptography/x509/extensions.py", line 13, in <module>
[1495734916365] ImportError: No module named pyasn1.codec.der
[1495734916366] [INFO] 2017-05-25T17:55:16.366Z 4e518819-4173-11e7-a448-3f29b99b1563 63.245.222.198 - - [25/May/2017:17:55:16 +0000] "GET / HTTP/1.1" 500 291 "" "python-requests/2.14.2" 0/134.167

gene1wood avatar May 25 '17 18:05 gene1wood

I've tested and confirmed the PR #50 fixes this bug.

gene1wood avatar May 25 '17 20:05 gene1wood