将pandas / scikit-learn包添加到项目以在AWS lambda中使用的正确方法是什么

时间:2015-11-20 00:18:29

标签: python pandas amazon-ec2 scikit-learn aws-lambda

我正在执行以下文档中提到的所有步骤: http://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html

我正在使用亚马逊linux的amazon的ec2来构建软件包。

我也尝试过做的提到的步骤 https://markn.ca/2015/10/python-extension-modules-in-aws-lambda/

以下是将包上传到AWS lambda并运行时出现的错误:

START RequestId: cbfe0762-8f1b-11e5-9a1d-49fb4d3a0d13 Version: $LATEST
Unable to import module 'test': No module named pandas

END RequestId: cbfe0762-8f1b-11e5-9a1d-49fb4d3a0d13
REPORT RequestId: cbfe0762-8f1b-11e5-9a1d-49fb4d3a0d13  Duration: 0.35 ms   Billed Duration: 100 ms     Memory Size: 128 MB Max Memory Used: 23 MB  

错误没有给出任何具体的指示。

使用更多详细信息进行修改:

嗨@maxymoo

我只是创建内容的zip。不是包含.py文件的文件夹。当我尝试使用我的.py文件添加“请求”包时,它工作正常。现在当我尝试使用我的.py文件添加“pandas”包时,它会给我上述错误。

以下是我要遵循的步骤:

  1. 使用运行它的amazon linux连接到ec2。

  2. 启动virtualenv

  3. 使用“pip install pandas”安装pandas

  4. 转到“/home/ec2-user/t1/lib/python2.7/site-packages”目录

  5. 获取“/home/ec2-user/t1/lib/python2.7/site-packages”的所有内容,将我的test.py文件添加到其中并创建zip文件

  6. 将zip文件上传到amazon lambda

  7. 运行测试

  8. 我收到以下错误:

    START RequestId: feee67de-8f2f-11e5-bc34-bd42a1d7326b Version: $LATEST
    Unable to import module 'test': No module named pandas
    
    END RequestId: feee67de-8f2f-11e5-bc34-bd42a1d7326b
    REPORT RequestId: feee67de-8f2f-11e5-bc34-bd42a1d7326b  Duration: 0.34 ms   Billed Duration: 100 ms     Memory Size: 128 MB Max Memory Used: 29 MB  
    

    test.py的内容是:

    import json
    
    import requests
    
    import pandas as pd
    
    
    print('Loading function')
    
    
    def lambda_handler(event, context):
    
        #print("Received event: " + json.dumps(event, indent=2))
    
        print("value1 = " + event['key1'])
    
        print("value2 = " + event['key2'])
    
        print("value3 = " + event['key3'])
    
        return event['key1']  # Echo back the first key value
    
        #raise Exception('Something went wrong')
    

    以下是zip文件中的文件:

    drwxrwxr-x  52 pds  staff     1768 Nov 19 17:09 setuptools
    
    drwxrwxr-x  32 pds  staff     1088 Nov 19 17:09 requests
    
    drwxrwxr-x  34 pds  staff     1156 Nov 19 17:10 pip
    
    drwxrwxr-x  11 pds  staff      374 Nov 19 17:10 setuptools-12.0.5.dist-info
    
    drwxrwxr-x  10 pds  staff      340 Nov 19 17:10 pip-6.0.8.dist-info
    
    drwxrwxr-x   8 pds  staff      272 Nov 19 17:10 requests-2.8.1.dist-info
    
    drwxrwxr-x   6 pds  staff      204 Nov 19 17:10 pkg_resources
    
    drwxrwxr-x   6 pds  staff      204 Nov 19 17:10 _markerlib
    
    -rw-r--r--@  1 pds  staff      374 Nov 19 17:15 test.py
    
    -rw-r--r--   1 pds  staff  3912745 Nov 19 17:16 Archive.zip
    
    -rw-r--r--   1 pds  staff      315 Nov 19 18:09 easy_install.pyc
    
    drwxrwxr-x   9 pds  staff      306 Nov 19 18:09 pytz-2015.7.dist-info
    
    -rw-r--r--   1 pds  staff    30098 Nov 19 18:10 six.py
    
    -rw-r--r--   1 pds  staff      126 Nov 19 18:10 easy_install.py
    
    drwxrwxr-x   8 pds  staff      272 Nov 19 18:11 six-1.10.0.dist-info
    
    drwxrwxr-x  15 pds  staff      510 Nov 19 18:11 pytz
    
    drwxrwxr-x   9 pds  staff      306 Nov 19 18:11 python_dateutil-2.4.2.dist-info
    
    -rw-r--r--   1 pds  staff    29545 Nov 19 18:11 six.pyc
    
    drwxrwxr-x  17 pds  staff      578 Nov 19 18:11 dateutil
    

0 个答案:

没有答案