AWS Lambda is a service whichallows named functions to be directly invoked (via a client API), have theirexecution triggered by a variety of AWS events (S3 upload, DynamoDB activity,etc.) or to serve as HTTP endpoints (via APIGateway).
This README serves to document a Leiningenplugin(lein-cljs-lambda
), template (cljs-lambda
) and smalllibrary (cljs-lambda
) to facilitate thewriting, deployment & invocation of Clojurescript Lambda functions.
The plugin can deploy functions itself, or theexcellent Serverless framework can be used,viaserverless-cljs-plugin.
:optimizations
:advanced
support, for smaller zip files*N.B. If using advanced compilation alongside Node's standard library,something likecljs-nodejs-externswill be required
This collection of projects is used extensively in production, for importantpieces of infrastructure. While efforts are made to ensure backwardcompatibility in the Leiningen plugin, the cljs-lambda
API is subject tobreaking changes.
io.nervous/lein-cljs-lambda
0.6.0 defaults the runtime of deployed functionsto nodejs4.3
, unless this is overriden with :runtime
in the fn-spec or onthe command-line. While your functions will be backwards compatible, your AWSCLI installation may require updating to support this change.$ lein new cljs-lambda my-lambda-project
$ cd my-lambda-project
$ lein cljs-lambda default-iam-role
$ lein cljs-lambda deploy
### 500ms delay via a promise (try also "delay-channel" and "delay-fail")
$ lein cljs-lambda invoke work-magic \
'{"spell": "delay-promise", "msecs": 500, "magic-word": "my-lambda-project-token"}'
... {:waited 500}
### Get environment varibles
$ lein cljs-lambda invoke work-magic \
'{"spell": "echo-env", "magic-word": "my-lambda-project-token"}'
...
$ lein cljs-lambda update-config work-magic :memory-size 256 :timeout 66
To generate a minimal project:
$ lein new serverless-cljs my-lambda-project
(Using promises)
(deflambda slowly-attack [{target :name} ctx]
(p/delay 1000 {:to target :data "This is an attack"}))
(Using core.async)
This function retrieves the name it was invoked under, then attempts to invokeitself in order to recursively compute the factorial of its input:
(deflambda fac [n {:keys [function-name] :as ctx}]
(go
(if (<= n 1)
n
(let [[tag result] (<! (lambda/request! (creds/env) function-name (dec n)))]
(* n result)))))
See theeulalie.lambda.utildocumentation for further details.
N.B. Functions interacting with AWS will require execution under roles with theappropriate permissions, and will not execute under the placeholder IAM rolecreated by the plugin's default-iam-role
task.
Using SNS & SQS from Clojurescript Lambda functions is covered in this workingexample,and the blogpostwhich discusses it.
$ lein cljs-lambda invoke my-lambda-fn '{"arg1": "value" ...}' [:region ...]
If you're interested in programmatically invoking Lambda functions fromClojure/Clojurescript, it's pretty easy witheulalie:
(eulalie.lambda.util/request!
{:access-key ... :secret-key ... [:token :region etc.]}
"my-lambda-fn"
{:arg1 "value" :arg2 ["value"]})
cljs-lambda is free and unencumbered public domain software. For moreinformation, see http://unlicense.org/ or the accompanying UNLICENSEfile.
问题内容: 我想了一下,想到了一个有趣的问题,假设我们有一个配置(输入)文件,其中: 此外,我们还有s 的列表: 有没有办法将s(等)转换为代表lambda表达式的s?然后可以用作: 我将如何编写这样的方法? 我可以从JDK / JRE中重用吗? 我需要自己编写所有内容吗? 是否有可能将范围缩小到仅捕获lambda的其他内容? 问题答案: 马可对这个问题的评论是正确的。您无法从文件中读取裸Java
问题内容: 在上一个问题中如何在Java 8中动态进行过滤?StuartMarks给出了一个很好的答案,并提供了一些有用的实用程序来处理从流中选择topN和topPercent。 我将从他的原始答案中将它们包括在这里: 我的问题是: [1]如何从具有一定数量项目的流中获取3到7的顶级项目,因此,如果流中有A1,A2 .... A10中的项目,则调用 将返回{A3,A4,A5,A6,A7} 我能想到
问题内容: 我是Java 8的新手,不确定如何使用流及其排序方法。如果我的地图如下,如何使用Java 8按值对地图进行排序以仅获取前10个条目。 我知道在Java 8之前,我们可以按以下链接进行排序:http://codingdict.com/questions/116310 问题答案: 您可以随时开始阅读文档和一些 教程。 参考 http://www.leveluplunch.com/java/
问题内容: 具体来说,我有TabPane,我想知道其中是否包含具有特定ID的元素。 因此,我想使用Java中的lambda表达式来做到这一点: 问题答案: 尝试使用Lambda表达式。这是更好的方法。
问题内容: 今天,在尝试学习有关JavaFX和Java的更多信息时,我遇到了我不太了解的另一件事。 参考是以下教程(旨在将原理应用到组织者): JavaFX 8教程 我将简要概述我遇到问题的特定部分: 我的主窗口包含一个显示一些约会数据的表格视图。所以我得到了这种风格的几行(与本教程相同): 可以通过附加的EditDialog操纵数据。那很好。如果我编辑内容,则更改会立即显示,但我进行了一些其他研
问题内容: 例如,在匿名内部类的情况下,传递(匿名)对象引用并执行该对象的方法。 Lambda是将在需要时执行的代码块。 遇到lambda时,JVM中会发生什么?JVM在哪里存储与lambda相关的代码块(堆:年轻,老旧或永久生成)? 我尝试搜索,但得到了使用lambda的语法,但无法理解JVM内部发生的情况,因为在JAVA中,一切都是基于对象的。 因此,在OOP中,lambda如何工作? lam