3

I have an AWS Lambda function that uses oauth2client and SignedJwtAssertionCredentials.

I have installed my requirements locally (at the root) of my Lambda function directory.

requirements.txt

boto3==1.2.5
gspread==0.3.0
oauth2client==1.5.2
pyOpenSSL==0.15.1
pycrypto==2.6.1

My lambda function looks like:

import boto3
import gspread
from oauth2client.client import SignedJwtAssertionCredentials

def lambda_handler(event, context):
    dynamodb = boto3.resource('dynamodb')
    scope = ['https://spreadsheets.google.com/feeds']

    private_key = "!--some-private-key"
    google_email = "some-email"
    credentials = SignedJwtAssertionCredentials(google_email, private_key, scope)
    gc = gspread.authorize(credentials)

However, when running this, I get the following stack trace:

{
    "stackTrace": [
        [
            "/var/task/lambda_function.py",
            20,
            "lambda_handler",
            "credentials = SignedJwtAssertionCredentials(google_email, private_key, scope)"
        ],
        [
            "/var/task/oauth2client/util.py",
            140,
            "positional_wrapper",
            "return wrapped(*args, **kwargs)"
        ],
        [
            "/var/task/oauth2client/client.py",
            1630,
            "__init__",
            "_RequireCryptoOrDie()"
        ],
        [
            "/var/task/oauth2client/client.py",
            1581,
            "_RequireCryptoOrDie",
            "raise CryptoUnavailableError('No crypto library available')"
        ]
    ],
    "errorType": "CryptoUnavailableError",
    "errorMessage": "No crypto library available"
}

From everything I've read online, I am told that I need to install pyopenssl. However, I already have that installed and pycrypto.

Is there something I'm missing?

1 Answer 1

3

Looks like this is a bit old of a question, but if you are still looking for an answer:

This occurs because one or more of the dependencies for pyopenssl is a native package or has native bindings (cryptography is a dependency of pyopenssl and has a dependency on libssl) that is not compiled for the target platform.

Unfortunately the process varies for how to get compiled versions. The simplest way (which works only if its a different in the platforms, not missing .so libraries) is to:

  1. Create an ec2 host (use t2.micro and the AWS AMI Image)
  2. Install python and virtualenv
  3. Create a virtual env
  4. Install your target library
  5. Zip up the virtualenv virtualenv/site-packages and virtualenv/dist-packages and move them off the machine
  6. Discard the machine image

This zip will then need to be expanded into your lambda zip before uploading. The result will be the required packages residing at the root of your zip file (not in site-packages or dist-packages folders)

For simple dependencies this works, if you require native libraries as well (such as for Numpy or Scipy) you will need to take more elaborate approaches such as the ones outlined here: http://thankcoder.com/questions/jns3d/using-moviepy-scipy-and-numpy-in-amazon-lambda

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

Comments

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.