无法在python AWS Lambda函数中运行二进制文件 [英] Can't run binary from within python aws lambda function
问题描述
我正在尝试在lambda函数中运行此工具: https://github.com/nicolas-f/7DTD-传单
I am trying to run this tool within a lambda function: https://github.com/nicolas-f/7DTD-leaflet
该工具取决于Pillow,后者取决于AWS lambda容器中不可用的映像库.为了解决这个问题,我运行了pyinstaller来创建可以希望执行的二进制文件.该文件名为map_reader
,位于lambda zip软件包的顶层.
The tool depends on Pillow which depends on imaging libraries not available in the AWS lambda container. To try and get round this I've ran pyinstaller to create a binary that I can hopefully execute. This file is named map_reader
and sits at the top level of the lambda zip package.
以下是我用来尝试运行该工具的代码:
Below is the code I am using to try and run the tool:
command = 'chmod 755 map_reader'
args = shlex.split(command)
print subprocess.Popen(args)
command = './map_reader -g "{}" -t "{}"'.format('/tmp/mapFiles', '/tmp/tiles')
args = shlex.split(command)
print subprocess.Popen(args)
这是错误,它在第二个subprocess.Popen
调用中发生:
And here is the error, which occurs on the second subprocess.Popen
call:
<subprocess.Popen object at 0x7f08fa100d10>
[Errno 13] Permission denied: OSError
如何正确运行此程序?
How can I run this correctly?
推荐答案
您可能被误导了问题的根源所在.
You may have been misled into what the issue actually is.
我不认为第一个Popen运行成功.我认为它只是在标准错误中转储了一条消息,而您却没有看到它.可能是说
I don't think that the first Popen ran successfully. I think that it just dumped a message in standard error and you're not seeing it. It's probably saying that
chmod: map_reader: No such file or directory
我建议您可以尝试以下2种方法之一:
I suggest you can try either of these 2:
- Extract the map_reader from the package into /tmp. Then reference it with
/tmp/map_reader
. - Do it as recommended by Tim Wagner, General Manager of AWS Lambda who said the following in the article Running Arbitrary Executables in AWS Lambda:
包含您自己的可执行文件很容易;只需将它们打包在您上载的ZIP文件中,然后在从Node.js或以前启动的其他进程中调用它们时就引用它们(包括创建的ZIP文件中的相对路径).确保在功能代码的开头包括以下内容:
process.env[‘PATH’] = process.env[‘PATH’] + ‘:’ + process.env[‘LAMBDA_TASK_ROOT’]
上面的代码适用于Node JS,但适用于Python,就像下面的
The above code is for Node JS but for Python, it's like the following
import os
os.environ['PATH']
import os
os.environ['PATH']
这应该使命令command = './map_reader <arguments>
起作用.
如果它们仍然不起作用,您还可以考虑在创建包并上传之前先chmod 755 map_reader
运行(如建议
If they still don't work, you may also consider running chmod 755 map_reader
before creating the package and uploading it (as suggested in this other question).
这篇关于无法在python AWS Lambda函数中运行二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!