博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
lambda ::_这是一个模拟器,而不是一个动物园:E和Lambda
阅读量:2520 次
发布时间:2019-05-11

本文共 5787 字,大约阅读时间需要 19 分钟。

lambda ::

When , we were excited to start using it. As you could see with , we put it to quick use, converting our skirmishes about lunch orders into a peaceful, democratic process.

当 ,我们很高兴开始使用它。 如您所见, 可以快速使用,将午餐订单方面的小冲突转变为和平,民主的过程。

Building Lambda functions is great, but there can be some challenges during development. There are many that we may yet cover, but the one we wanted to start with was just writing and debugging the function. As such, we wanted to build a local harness for lambda functions that could shorten the feedback loop on development, be used for attaching debuggers, drive test data through the function, and profile it as well so we’d have an idea what it would cost to run.

构建Lambda函数很棒,但是在开发过程中可能会遇到一些挑战。 我们可能涵盖了许多内容,但是我们想开始的只是编写和调试函数。 因此,我们想为lambda函数构建一个本地工具,该函数可以缩短开发过程中的反馈循环,可用于附加调试器,通过该函数驱动测试数据并对其进行概要分析,因此我们将了解其功能。运行成本。

To do this, we developed Emulambda. To be clear, that’s a portmanteau of the words “emulator” and “lambda,” but if you want to think it’s some sort of anonymous emu, go for it! Emulambda, just like AWS Lambda, works with Python 2.7.

为此,我们开发了Emulambda。 明确地说,这是“仿真器”和“ lambda”两个词的组合,但是如果您想以为它是某种匿名e,那就去吧! Emulambda与AWS Lambda一样,都可与Python 2.7一起使用。

Installing Emulambda is simple:

安装Emulambda很简单:

  1. git clone
  2. Install it with pip install -e emulambda (You might need to sudo this command if you’re using your system Python instead of a virtualenv or similar.)
  1. git clone
  2. 使用pip install -e emulambda安装它(如果使用系统Python而不是virtualenv或类似的软件,则可能需要sudo此命令。)

These steps should make the emulambda script available as a runnable file in your path. The -e argument means the installation is “editable,” so that you can hack on it if you need or want to. Soon, we’ll put the project in PyPi and update these instructions to be even easier.

这些步骤应使emulambda脚本在您的路径中作为可运行文件可用。 -e参数表示安装是“可编辑的”,因此您可以根据需要修改该安装。 很快,我们会将项目放入PyPi,并更新这些说明以使其更加容易。

The repository comes with an example lambda function and example event document to show you exactly how this works. The simplest way to run Emulambda is to simply give an import path for your function and an event JSON document. You can run the example from the repository root with this command:

该存储库附带一个示例lambda函数和示例事件文档,以向您确切说明其工作方式。 运行Emulambda的最简单方法是简单地为函数和事件JSON文档提供导入路径。 您可以使用以下命令从资源库根目录运行示例:

emulambda example.example_handler example/example.jsonemulambda example.example_handler example/example.json

This will print the return value of the function to stdout, like so:

这会将函数的返回值打印到stdout,如下所示:

If you want a little more information, add the -v switch.

如果需要更多信息,请添加-v开关。

Executed example.example_handlerEstimated......execution clock time:         157ms (200ms billing bucket)...execution peak RSS memory:         368M (385888256 bytes)----------------------RESULT----------------------value1Executed example.example_handlerEstimated......execution clock time:         157ms (200ms billing bucket)...execution peak RSS memory:         368M (385888256 bytes)----------------------RESULT----------------------value1

Now, we have an idea what our function takes to run. You can also set a timeout for the function, just as you can in AWS, so that tests can fail if the function takes too long. The timing and memory usage measurements are based on informed guesses about how AWS determines these things, but they should be viewed as approximate at best. Over time we might be able to refine these estimates. You can find out more about the profiling mechanism in .

现在,我们知道了函数需要执行的操作。 您也可以像在AWS中一样为该函数设置超时,以便如果该函数花费太长时间,测试可能会失败。 时间和内存使用情况的测量基于有关AWS如何确定这些事情的明智猜测,但充其量应视为最佳。 随着时间的流逝,我们也许可以完善这些估计。 您可以在找到有关配置机制的更多信息。

Another cool thing you can do is send the event into the function via stdin. Just use the - (dash) character in place of a filename, like this:

您可以做的另一件很酷的事情是通过stdin将事件发送到函数中。 只需使用- (破折号)字符代替文件名即可,如下所示:

Since stdin is supported by… well, everything that uses stdout, you can easily integrate Emulambda with other scripts or utilities.

由于stdin受……好,所有使用stdout的东西都支持,因此您可以轻松地将Emulambda与其他脚本或实用程序集成。

The input document can be either a single JSON document, or a Line-Delimited JSON (LDJSON) stream. In either case, a file or stdin can be used. For more information on the LDJSON stream support, .

输入文档可以是单个JSON文档,也可以是行分隔JSON(LDJSON)流。 无论哪种情况,都可以使用文件或标准输入。 有关LDJSON流支持的更多信息, 。

We hope Emulambda is useful to you at both development and test time when you’re working with AWS Lambda.

我们希望Emulambda在使用AWS Lambda时在开发和测试时对您都有用。

For development, you can

为了发展,你可以

  • run your lambda functions instantly locally, without packaging and sending to AWS;
  • shorten your feedback loop on lambda executions; and
  • easily attach debuggers to your lambda.
  • 无需打包并发送到AWS即可在本地立即运行lambda函数;
  • 缩短关于lambda执行的反馈循环; 和
  • 轻松将调试器附加到您的lambda。

And for testing, Emulambda lets you

为了进行测试,Emulumbda可让您

  • easily integrate with test tools using a simple CLI and various input methods;
  • use stream mode to test many cases or run fuzz tests; and
  • use profiling information to identify expensive/problematic lambdas early.
  • 使用简单的CLI和各种输入法轻松地与测试工具集成;
  • 使用流模式来测试许多情况或运行模糊测试; 和
  • 使用配置文件信息尽早识别昂贵/有问题的lambda。

Some future features we’d like to see in the project:

我们希望在项目中看到一些将来的功能:

  • SQS Support (though for now, you can easily pipe AWS CLI output to Emulambda stdin)
  • Kinesis support / emulation
  • An AWS event library, for common integrations with other services
  • Context support! Probably an optional argument to provide context objects in the same way as event objects.
  • SQS支持(尽管到目前为止,您可以轻松地将AWS CLI输出通过管道传输到Emulambda stdin)
  • Kinesis支持/仿真
  • 一个AWS事件库,用于与其他服务的常见集成
  • 上下文支持! 可能是一个可选参数,用于以与事件对象相同的方式提供上下文对象。

We are excited about the opportunities in serverless computing, and how Fugue will support you in pursuing those opportunities in the near future.

我们对无服务器计算方面的机会以及Fugue将如何在不久的将来支持您的机会感到兴奋。

.

Share

分享

Twitter

推特

Reddit

Reddit

Google+

Google+

Facebook

脸书

翻译自:

lambda ::

转载地址:http://gqqwd.baihongyu.com/

你可能感兴趣的文章
开发 笔记
查看>>
数据挖掘算法比赛 - 简单经验总结
查看>>
win7(64位)php5.5-Apache2.4-mysql5.6环境安装
查看>>
生成商户订单号/退款单号
查看>>
git使用——分支
查看>>
selenium之多线程启动grid分布式测试框架封装(一)
查看>>
突然的伤感
查看>>
Objective-C 链式编程思想
查看>>
开通了一个微信公众账号,主要想分享一些自己对于行业、技术和产品的思考以及收录精彩内容给读者...
查看>>
留言板
查看>>
c#$用法
查看>>
js通过as完成socket通信
查看>>
关于我书里提到的“挂多个类,使用类的组合”的一些补充
查看>>
JavaScrip中的循环语句
查看>>
IntelliJ IDEA和Webstorm 的下载安装、注册码(永久有效)
查看>>
停止使用非版本控制的可执行代码
查看>>
Php5.3的lambda函数以及closure(闭包)
查看>>
inotify监测实例
查看>>
C#程序如何把窗体文件从从一个项目中复制到另一个项目
查看>>
Android金背大刀之ToggleButton之稍息立正
查看>>