本地编译Python库无服务器与无服务器的Python-要求

问题描述 投票:0回答:1

我试图编译numpy的在AWS lambda函数使用从我的Windows机器。

我一直在下面的无服务器的Python-要求this简单的例子,一个拉姆达打印numpy的阵列。

我在本地目录serverless deploy运行../numpy-test从virtualenv中内

(numpy-test) C:\Users\...\numpy-test>serverless deploy
Serverless: Generated requirements from C:\Users\...\numpy-test\requirements.txt in C:\Users\...\numpy-test\.serverless\requirements.txt...
Serverless: Installing requirements from C:\Users\...\numpy-test\.serverless\requirements\requirements.txt ...
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Injecting required Python packages to package...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (42.86 MB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...

我requirements.txt文件只包含

numpy==1.13.1

我的YML文件的样子:

service: numpy-test 

frameworkVersion: ">=1.1.0 <2.0.0"

plugins:
  - serverless-domain-manager
  - serverless-python-requirements
custom:
  pythonRequirements:
    dockerizePip:non-linux

  stage: ${opt:stage, self:provider.stage}
  domains:
    prod: ...
    staging: ...
    dev: ...

当我尝试上传与serverless invoke -f numpy --log后测试功能我得到以下错误

    "errorMessage": "Unable to import module 'handler'"
}
--------------------------------------------------------------------
START RequestId: 24584f5c-5145-4694-b21b-7c6e4700f985 Version: $LATEST
Unable to import module 'handler':
Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control).  Otherwise reinstall numpy.

Original error was: cannot import name 'multiarray'

当我直接从AWS拉姆达下载的依赖,它看起来像包在Windows编译。

enter image description here

我有泊坞窗安装并尽可能我可以告诉它的正常工作。之前,所以这就是为什么我试图使用该解决方案,而不是学习了很多的在泊坞新命令我没有用它。

这是怎么回事了?

numpy docker python-3.6 serverless-framework aws-serverless
1个回答
1
投票

我不知道究竟是什么在你的情况怎么回事,但如果你想在LAMBDA使用numpy,看看Lambda Layers and the official (AWS) layernumpyscipy

要使用它,在你serverless.yml一个layers section添加到函数

functions:
  myFunction:
    layers:
      - arn:aws:lambda:us-east-1:668099181075:layer:AWSLambda-Python36-SciPy1x:2

您可能需要改变取决于你所定位的AWS区域的ARN。

© www.soinside.com 2019 - 2024. All rights reserved.