Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python-jose not part of the lambda environment? #34

Closed
Wood-Chopper opened this issue Feb 26, 2018 · 4 comments
Closed

python-jose not part of the lambda environment? #34

Wood-Chopper opened this issue Feb 26, 2018 · 4 comments

Comments

@Wood-Chopper
Copy link

Hello, I am trying to use the code here to verify if a token is valid
/Cognito/decode-verify-jwt/decode-verify-jwt.py
But I am facing an issue. My Lambda doesn't recognize jose.
Unable to import module 'lambda_function': No module named 'jose'

@emanuelem
Copy link
Contributor

Hello,

Thank you for pointing that out. It actually seems that python-jose is not part of the Lambda environment anymore.
At this point, the only way is to add it to the Lambda deployment package.

@Wood-Chopper
Copy link
Author

Thanks for answering me.
However, when adding a deployment package, I run into another error:
module initialization error: Cannot load native module 'Crypto.Hash._SHA256': Trying '_SHA256.so': /var/task/Crypto/Util/../Hash/_SHA256.so: invalid ELF header, Trying '_SHA256module.so': /var/task/Crypto/Util/../Hash/_SHA256module.so: cannot open shared object file: No such file or directory
I am using Python 2.7

@emanuelem
Copy link
Contributor

The error "invalid ELF header" means that the binaries you added to the deployment package were compiled for another architecture. For example, it is common to see this error if the package was installed with "pip" under Mac.

An easy solution is to spin up an EC2 instance, then install the modules and create the deployment package there. This will include the same binaries used by the Lambda environment.

@Wood-Chopper
Copy link
Author

Wood-Chopper commented Mar 2, 2018

Solution:
I launched an EC2 instance as you suggested, but with the same environment as Lambdas (just to be sure).
Lambda AMI

Execute this on EC2. This creates the deployment package and sends it to a S3 bucket :

$sudo yum group install "Development Tools"
$mkdir lambda
$sudo pip install --upgrade pip
$hash -r
$pip install python-jose -t lambda/
$pip install cryptography -t lambda/
$zip -r Archive.zip lambda
$aws configure
$aws s3api put-object --bucket <<Bucket_Name>> --key Archive.zip --body Archive.zip 

Thank you for your help !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants