简体   繁体   English

AWS Lambda未检测到pyopenssl

[英]AWS Lambda not detecting pyopenssl

I have an AWS Lambda function that uses oauth2client and SignedJwtAssertionCredentials . 我有一个AWS Lambda函数,它使用oauth2clientSignedJwtAssertionCredentials

I have installed my requirements locally (at the root) of my Lambda function directory. 我已经在我的Lambda函数目录的本地(在根目录)安装了我的需求。

requirements.txt 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: 我的lambda函数看起来像:

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. 从我在网上看到的一切,我被告知我需要安装pyopenssl。 However, I already have that installed and pycrypto. 但是,我已经安装了pycrypto。

Is there something I'm missing? 有什么我想念的吗?

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. 发生这种情况是因为pyopenssl的一个或多个依赖项是本机程序包,或者具有本机绑定(加密是pyopenssl的依赖项并且依赖于libssl),而不是为目标平台编译的。

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: 最简单的方法(只有在平台上有所不同,而不是缺少.so库)才能:

  1. Create an ec2 host (use t2.micro and the AWS AMI Image) 创建ec2主机(使用t2.micro和AWS AMI映像)
  2. Install python and virtualenv 安装python和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 拉上virtualenv virtualenv / site-packages和virtualenv / dist-packages并将它们从机器上移开
  6. Discard the machine image 丢弃机器图像

This zip will then need to be expanded into your lambda zip before uploading. 然后,在上传之前,需要将此zip文件扩展为lambda zip。 The result will be the required packages residing at the root of your zip file (not in site-packages or dist-packages folders) 结果将是驻留在zip文件根目录中的必需软件包(不在site-packages或dist-packages文件夹中)

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 对于简单的依赖项,如果您需要本机库(例如Numpy或Scipy),则需要采用更详细的方法,例如此处列出的方法: http//thankcoder.com/questions/jns3d/using- moviepy-SciPy的-和numpy的功能于亚马逊拉姆达

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM