AWS Lambda是否可以通过Wine运行Windows二进制文件? [英] Is it possible for AWS Lambda to run a Windows binary via Wine?

查看:162
本文介绍了AWS Lambda是否可以通过Wine运行Windows二进制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有Windows .exe依赖项的Python脚本,而该依赖项又依赖于(封闭源代码)Windows DLL.通过调用Wine,Python脚本可以在Ubuntu中正常运行.

I have a Python script with a Windows .exe dependency, which in return relies on a (closed-source) Windows DLL. The Python script runs just fine in Ubuntu via a call to Wine.

是否可以(并且实际)在AWS Lambda上运行它?

Is it possible (and practical) to run this on AWS Lambda?

准备代码包会涉及什么?

What would be involved in preparing the code package?

推荐答案

TL; DR;

有可能吗?

实用吗?我尝试的方法不是.更好的方法可能是尝试将葡萄酒放入不同的lambda层或自定义执行环境中.

Is it practical? The approach I tried is not. A better approach might be to try and put wine into different lambda layers or a custom execution environment.

它对您有用吗? 这取决于,部署程序包的大小和磁盘空间是限制因素.

Will it work for you? It depends, deployment package size and disk space are the limiting factors.

我为lambda编译了一个具有最小依赖性的自定义酒,将其压缩,然后将其放到S3上.

I compiled a custom wine with minimal dependencies for lambda, compressed it and then put it onto S3.

然后,在运行时在lambda中,我下载了存档,将其提取到/tmp并使用自定义的空wine前缀运行.

Then, in the lambda at runtime, I downloaded the archive, extracted it to /tmp and ran it with a custom empty wine prefix.

我的测试Windows可执行文件为64位 curl.exe .

My test windows executable was 64bit curl.exe.

来自 https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html ,我首先尝试使用amzn-ami-hvm-2018.03.0.20181129-x86_64-gp2,但是它具有较旧的编译环境,因此无法配置.

From https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html, I first tried amzn-ami-hvm-2018.03.0.20181129-x86_64-gp2, but it had an older compilation environment and wouldn't configure.

t3.2xlarge ec2上使用AMI amzn2-ami-hvm-2.0.20190313-x86_64-gp2,我能够进行配置和编译.这些是我使用的命令,引用了 aws-compile 建筑葡萄酒:

With AMI amzn2-ami-hvm-2.0.20190313-x86_64-gp2 on a t3.2xlarge ec2, I was able to configure and compile. These are the commands I used, references aws-compile and building-wine:

> sudo yum groupinstall "Development Tools"
> mkdir -p ~/wine-dirs/wine-source
> git clone git://source.winehq.org/git/wine.git ~/wine-dirs/wine-source
> cd ~/wine-dirs/wine-source
> ./configure --enable-win64 --without-x --without-freetype --prefix /opt/wine
> make -j8
> sudo mkdir -p /opt/wine
> sudo chown ec2-user.ec2-user /opt/wine/
> make install
> cd /opt/
> tar zcvf ~/wine-64.tar.gz wine/

这只是一个64位版本.它还几乎没有其他可选的Wine依赖项.

This was only a 64-bit build. It also had almost no other optional wine dependencies.

在编译时,我从wine构建中删除了很多可选的依赖项,但是它仍然太大. /tmp 限制为500MB .

I removed a lot of optional dependencies from the wine build at compilation time, but it was still too big. /tmp is limited to 500MB.

我删除了包子目录中的文件,包括看起来像可选的lib,直到我将其压缩到大约300MB为止.

I deleted files in the package subdirectories, including what looked like optional libs, until I got it down to around 300MB uncompressed.

我验证了从构建中删除文件后wine仍然可以运行curl.exe.

I verified that wine would still run curl.exe after deleting files from the build.

我使用默认的bz2选项创建了酒和卷发的tar.bz2,最终的大小约为80MB.压缩和解压缩的文件总共需要大约390MB.

I created a tar.bz2 of wine and curl with default bz2 options, it ended up around 80MB. The compressed and extracted files together required about 390MB.

这样,就有足够的空间来下载存档并将其解压缩到lambda内的/tmp中.

That way there is enough room to both download the archive and extract it to /tmp inside the lambda.

> du -h .
290M    ./wine/lib64/wine
292M    ./wine/lib64
276K    ./wine/share/wine
8.0K    ./wine/share/applications
288K    ./wine/share
5.0M    ./wine/curl-7.66.0-win64-mingw/bin
5.0M    ./wine/curl-7.66.0-win64-mingw
12M     ./wine/bin
308M    ./wine
390M    .

> ls
wine wine.tar.bz2

4.将wine.tar.bz2上传到S3

创建一个S3存储桶,然后将wine.tar.bz2文件上传到其中.

4. Upload wine.tar.bz2 to S3

Create an S3 bucket and upload the wine.tar.bz2 file to it.

使用python 3.7运行时创建一个AWS Lambda.尽管它使用了与上面构建的葡萄酒不同的底层AMI,但它仍然有效.

Create an AWS Lambda using the python 3.7 runtime. While this uses a different underlying AMI than what wine was built on above, it still worked.

在lambda执行角色中,授予对S3存储桶的访问权限.

In the lambda execution role, grant access to the S3 bucket.

RAM:1024MB.我之所以选择它,是因为lambda CPU 功耗随内存而定

RAM: 1024MB. I chose this because lambda CPU power scales with the memory.

超时:1 min

我需要听从问题和答案中的建议以进行更改Lambda内的葡萄酒前缀.我还按照建议关闭了显示器.

I needed to follow the advice from this question and answer to change the wine prefix inside the lambda. I also turned off the display as it suggested.

例如:

handler():
  ... download from S3 to /tmp, cd to /tmp

  subprocess.call(["tar", "-jxvf", "./wine.tar.bz2"])

  os.environ['DISPLAY'] = ''
  os.environ['WINEARCH'] = 'win64'
  os.environ['WINEPREFIX'] = '/tmp/wineprefix'

  subprocess.call(["./wine/bin/wine64", "./wine/curl-7.66.0-win64-mingw/bin/curl.exe", "http://www.stackoverflow.com"])

成功!

这篇关于AWS Lambda是否可以通过Wine运行Windows二进制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆