aws 部署python lambda,Python限制中的AWS Lambda部署软件包

I want to run my code on AWS lambda function. To do so, i need to import some python packages (i.e. pandas, numpy, sklearn, scipy)

I have two problems:

First of all, the size of (unzip) packaged python zip files is greater than 250MB.

Secondly, I got some error using scipy as well as sklearn as:

Unable to import module 'lambda_function': cannot import name

'_ccallback_c'

of

Unable to import module 'lambda_function': No module named

'sklearn.check_build._check_build'

___________________________________________________________________________ Contents of /var/task/sklearn/__check_build:

__pycache _check_build.cpython-35m-x86_64-linux-gnu.sosetup.py

init.py

___________________________________________________________________________ It seems that scikit-learn has not been built correctly.

I tried to reinstall many times...

But still problems in sklearn and scipy.

Any idea?

sample code in AWS LambdaFunction:

import json

import numpy

import pandas

import sklearn

import scipy

def lambda_handler(event, context):

# TODO implement

print(event)

return

解决方案

You appear to have two issues.

The first (and easiest to solve) is that you need to install the relevant modules on a Linux distro comparable to Amazon Linux.

You can either do this using EC2 or in a Docker container with Amazon Linux on it.

The second issue (which is a bit trickier if not impossible to solve given the size of the modules you want to use) is that you need to get your deployment size down to under 250MB unzipped and under 50MB zipped.

Using relevant CFLAG when installing may get you some of the way there. See here for an idea of what might work.

If you are still over limit (which I suspect you will be) your only choice left will be to delete some of the files in the modules which you believe will not be used in your particular program. This is risky, often error prone and usually takes many attempts to get right. Using code coverage tools may help you here, as they can indicate which files are actually being used.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值