如何编译节点C ++插件,以便可以在Amazon AWS上分发它? [英] How can I compile a node C++ addon so that I can use distribute it on amazon AWS?
问题描述
AWS lambda不支持在系统上安装linux二进制文件,您必须在系统中包括可执行文件.对于已经提供了静态可执行文件的 ffmpeg 这样的可执行文件,这将很容易.
对于使用node-gyp
编译的节点二进制附件,这将如何工作?只需在Linux环境中包含build/
目录即可吗?
有人知道吗?
在我们的例子中,它是使用node-gyp
构建的node-dv模块.通过以下步骤可以使其正常工作:
-
生成新的EC2实例.确保它基于与您的AWS Lambda运行时完全相同的映像.您可以在此处查看Lambda env详细信息: http://docs .aws.amazon.com/lambda/latest/dg/current-supported-versions.html .在我们的案例中,它是称为 amzn-ami-hvm-2015.03.0.x86_64-gp2 的Amazon Linux AMI.
-
安装
nvm
并使用它安装与AWS Lambda上相同版本的Node.js.在撰写本文时,它是 v0.10.36 .您可以参考 http://docs.aws.amazon再次查找.com/lambda/latest/dg/current-supported-versions.html . -
您可能需要安装git& EC2上的g ++编译器.您可以运行此
sudo yum install git gcc-c++
-
最后,将您的应用程序克隆到新的EC2并安装您的应用程序的依赖项:
nvm use 0.10.36 npm install --production
AWS lambda does not support installing linux binaries on the system, you would have to include the executables on your system. this would be easy for executables such as ffmpeg that already supply static executables.
How would this work for node binary addons that are compiled to using node-gyp
? Would simply including the build/
directory from a linux environment work?
Has anyone figured this out yet?
In our case, it was node-dv module, which is built using node-gyp
. The following steps make it work:
Spawn new EC2 instance. Make sure it is based on exactly the same image as your AWS Lambda runtime. You can review Lambda env details here: http://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html. In our case, it was Amazon Linux AMI called amzn-ami-hvm-2015.03.0.x86_64-gp2.
Install
nvm
and use it to install the same version of Node.js as on the AWS Lambda. At the time of writing this, it was v0.10.36. You can refer to http://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html again to find out.You will probably need to install git & g++ compiler on the EC2. You can do this running
sudo yum install git gcc-c++
Finally, clone your app to your new EC2 and install your app's dependecies:
nvm use 0.10.36 npm install --production
这篇关于如何编译节点C ++插件,以便可以在Amazon AWS上分发它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!