我正在尝试从Windows机器上编译numpy以用于AWS Lambda函数。
我一直在跟踪{strong> serverless-python-requirements 的一个简单示例,以使Lambda打印一个numpy数组。
我从本地目录serverless deploy
的virtualenv内部运行../numpy-test
(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 lambda下载依赖项时,看起来该软件包是在Windows中编译的。
我已经安装了Docker,据我所知它运行正常。我以前从未使用过它,所以这就是为什么我尝试使用此解决方案而不是在Docker中学习许多新命令的原因。
出了什么问题?
答案 0 :(得分:1)
我不确定您的情况到底是怎么回事,但是如果您想在Lambda中使用numpy
,请使用numpy
和{{1 }}。
要使用它,请将Lambda Layers and the official (AWS) layer添加到serverless.yml中的函数中。
scipy
您可能需要根据要定位的AWS区域更改ARN。