我正在尝试在AWS lambda函数中调用python脚本。我为python创建了一个虚拟环境,并安装了需要的pandas,pymongo等模块。这是我的invokepython.js:
var exec = require('child_process').exec;
exports.handler = function(event, context) {
console.log('Received event:', JSON.stringify(event, null, 2));
exec("env/bin/python kinesisconsumer.py '"+ JSON.stringify(event) +"'", function(error, stdout) {
console.log('Python returned: ' + stdout + '.');
context.done(error, stdout);
});
};
我已安装virtualenv
并使用它创建了一个env。使用env/bin/pip install pandas
我已经安装了pandas。我已经将env文件夹和我的脚本压缩在一起并将其部署到AWS lambda但是收到错误。
{
"errorMessage": "Command failed: Traceback (most recent call last):\n File \"kinesisconsumer.py\", line 4, in <module>\n import pandas as pd\n File \"/var/task/env/local/lib/python2.7/site-packages/pandas/__init__.py\", line 13, in <module>\n \"extensions first.\".format(module))\nImportError: C extension: libcrypto.so.1.0.0: cannot open shared object file: No such file or directory not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace' to build the C extensions first.\n",
"errorType": "Error",
"stackTrace": [
" File \"kinesisconsumer.py\", line 4, in <module>",
" import pandas as pd",
" File \"/var/task/env/local/lib/python2.7/site-packages/pandas/__init__.py\", line 13, in <module>",
" \"extensions first.\".format(module))",
"ImportError: C extension: libcrypto.so.1.0.0: cannot open shared object file: No such file or directory not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace' to build the C extensions first.",
"",
"ChildProcess.exithandler (child_process.js:658:15)",
"ChildProcess.emit (events.js:98:17)",
"maybeClose (child_process.js:766:16)",
"Process.ChildProcess._handle.onexit (child_process.js:833:5)"
]
我需要在AWS lambda上使用pandas。我应该如何解决这个问题。任何帮助表示赞赏!!!
答案 0 :(得分:0)
我在Amazon Linux上做的就像我在ubuntu机器上做的那样。它的工作。解释here
为了在AWS Lambda中工作,需要为Amazon Linux x86_64编译扩展模块&#34;