Amazon Web Services Lambda函数中的Perl脚本 [英] Perl script in Amazon Web Services Lambda functions

查看:108
本文介绍了Amazon Web Services Lambda函数中的Perl脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能通过 Amazon Web Services 中的lambda函数运行Perl程序?

Is there any possibility of running a Perl program from lambda functions in Amazon Web Services?

推荐答案

只要Lambda与Lambda运行时环境二进制兼容且可以放入部署包中,您就可以在Lambda中运行任何内容.但是您必须将其包装在以一种受支持的语言编写的函数中.这出乎意料地比您预期的更加有效和高效,特别是如果您可以使用其他语言编写代码,以便可以在每个容器中生成一次代码并与Lambda函数交换序列化消息,尤其如此.或者,您每次调用只能运行一次外部程序.

You can run essentially anything in Lambda as long as it is binary-compatible with the Lambda runtime environment and can fit into a deployment package. But you have to wrap it in a function written in one of the supported languages. This is surprisingly more effective and efficient than you might expect, particularly if you can write your code in the other language so that it can be spawned once per container and exchange serialized messages with the Lambda function. Or, you can just run the external program once per invocation.

Lambda控制台中有一个名为node-exec的蓝图",它说明了一个简单的示例.其来源是:

There is a "blueprint" in the Lambda console called node-exec that illustrates a simple example. Its source is this:

'use strict';

const exec = require('child_process').exec;

exports.handler = (event, context, callback) => {
    if (!event.cmd) {
        return callback('Please specify a command to run as event.cmd');
    }
    const child = exec(event.cmd, (error) => {
        // Resolve with result of process
        callback(error, 'Process complete!');
    });

    // Log process stdout and stderr
    child.stdout.on('data', console.log);
    child.stderr.on('data', console.error);
};

这足以让您了解如何完成此操作.

It's just enough to give you the idea of how it can be done.

Lambda/Node 6运行时环境上的系统Perl是perl5(修订版5版本16的版本3).

The system Perl on the Lambda/Node 6 runtime environment is perl5 (revision 5 version 16 subversion 3).

在其中一种使用本机支持的语言可以同样有效地完成任务的地方,使用其中一种支持的语言几乎可以肯定是要走的路...而且,如果您了解Perl,尤其是如果您还使用异步框架,像Mojolicious一样,您可能会在相对较短的时间内提高Node的生产力.

Where the task can be accomplished equally effectively with one of the natively supported languages, using one of the supported languages is almost certainly the way to go... and if you know Perl and particularly if you have also worked with asynchronous frameworks like Mojolicious, you're potentially not far off from being able to be productive with Node in a relatively short time.

但是,在Lambda中运行Perl对我来说是一个合适的选择的示例是解码使用 Storable::freeze()序列化的旧数据. ,然后在base64中进行编码.可存储是Perl特有的序列化格式.我的Node Lambda函数将事件数据作为JSON上的JSON传递给Perl脚本(以child_process.exec生成),然后将解码结果(也在JSON中)写入STDOUT,由Node代码捕获它并调用回调. Perl脚本在两次调用之间继续运行.在已预热的容器上进行整个调用的运行时小于<. 4毫秒.

But one example where running Perl in Lambda was an appropriate choice for me was decoding legacy data serialized with Storable::freeze() and then encoded in base64. Storable is a serialization format that is specific to Perl. My Node Lambda function passes the event data to the Perl script (spawned with child_process.exec) as JSON on STDIN, which writes the decoded result (also in JSON) to STDOUT, where the Node code captures it and invokes the callback. The Perl script continues running between invocations. Runtime for the entire invocation on a warmed up container is < 4 ms.

这篇关于Amazon Web Services Lambda函数中的Perl脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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