nervous-systems/cljs-lambda


Utilities around deploying Clojurescript functions to AWS Lambda

License: Unlicense

Language: Clojure

Keywords: aws, aws-lambda, clojure, clojurescript, leiningen, nodejs, serverless


cljs-lambda

Build Status

AWS Lambda is a service which allows named functions to be directly invoked (via a client API), have their execution triggered by a variety of AWS events (S3 upload, DynamoDB activity, etc.) or to serve as HTTP endpoints (via API Gateway).

This README serves to document a Leiningen plugin (lein-cljs-lambda), template (cljs-lambda) and small library (cljs-lambda) to facilitate the writing, deployment & invocation of Clojurescript Lambda functions.

The plugin can deploy functions itself, or the excellent Serverless framework can be used, via serverless-cljs-plugin.

Benefits

  • Low instance warmup penalty
  • Use promises, or asynchronous channels for deferred completion
  • :optimizations :advanced support, for smaller zip files*
  • Utilities for testing Lambda entrypoints off of EC2
  • Function publishing/versioning
  • Serverless integration

N.B. If using advanced compilation alongside Node's standard library, something like cljs-nodejs-externs will be required

Status

This collection of projects is used extensively in production, for important pieces of infrastructure. While efforts are made to ensure backward compatibility in the Leiningen plugin, the cljs-lambda API is subject to breaking changes.

Recent Changes

  • io.nervous/lein-cljs-lambda 0.6.0 defaults the runtime of deployed functions to nodejs4.3, unless this is overriden with :runtime in the fn-spec or on the command-line. While your functions will be backwards compatible, your AWS CLI installation may require updating to support this change.

Coordinates

Plugin

Clojars Project

Library

Clojars Project

Get Started

$ lein new cljs-lambda my-lambda-project
$ cd my-lambda-project
$ lein cljs-lambda default-iam-role
$ lein cljs-lambda deploy
$ lein cljs-lambda invoke work-magic \
  '{"spell": "delay-promise", "magic-word": "my-lambda-project-token"}'
...
$ lein cljs-lambda update-config work-magic :memory-size 256 :timeout 66

Serverless

To generate a minimal project:

$ lein new serverless-cljs my-lambda-project

Documentation

Older

Other

Function Examples

(Using promises)

(deflambda slowly-attack [{target :name} ctx]
  (p/delay 1000 {:to target :data "This is an attack"}))

AWS Integration With eulalie

(Using core.async)

This function retrieves the name it was invoked under, then attempts to invoke itself 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 the eulalie.lambda.util documentation for further details.

N.B. Functions interacting with AWS will require execution under roles with the appropriate permissions, and will not execute under the placeholder IAM role created by the plugin's default-iam-role task.

Further Examples

Using SNS & SQS from Clojurescript Lambda functions is covered in this working example, and the blog post which discusses it.

Invoking

CLI

$ lein cljs-lambda invoke my-lambda-fn '{"arg1": "value" ...}' [:region ...]

Programmatically

If you're interested in programmatically invoking Lambda functions from Clojure/Clojurescript, it's pretty easy with eulalie:

(eulalie.lambda.util/request!
 {:access-key ... :secret-key ... [:token :region etc.]}
 "my-lambda-fn"
 {:arg1 "value" :arg2 ["value"]})

License

cljs-lambda is free and unencumbered public domain software. For more information, see http://unlicense.org/ or the accompanying UNLICENSE file.

Project Statistics

Sourcerank 8
Repository Size 188 KB
Stars 287
Forks 33
Watchers 15
Open issues 13
Dependencies 0
Contributors 11
Tags 16
Created
Last updated
Last pushed

Top Contributors See all

Moe Aboulkheir daniel heidebrecht Zrzka Honza Břečka Alessandro Decina Igor Bondarenko David A. Viramontes Viktor Eriksson Brent Hagany Aleksander Sumowski Paul Butcher

Packages Referencing this Repo

io.nervous/cljs-lambda
Clojurescript AWS Lambda utilities
Latest release 0.3.6-SNAPSHOT - Updated - 287 stars
serverless-cljs/lein-template
Clojurescript on AWS Lambda via Serverless
Latest release 0.1.3 - Updated - 287 stars
cljs-lambda/lein-template
Clojurescript on AWS Lambda
Latest release 0.4.10 - Updated - 287 stars

Recent Tags See all

0.6.6 May 12, 2017
0.6.5 March 13, 2017
0.6.4 February 06, 2017
0.6.3 November 28, 2016
0.6.2 September 07, 2016
0.6.1 August 19, 2016
0.6.0 July 20, 2016
0.5.2 May 29, 2016
0.5.1 March 20, 2016
v0.5.0 March 10, 2016
v0.4.0 February 13, 2016
v0.3.0 January 16, 2016
v0.2.4 August 10, 2015
v0.2.3 August 09, 2015
v0.2.2 August 08, 2015

Something wrong with this page? Make a suggestion

Last synced: 2017-06-12 16:39:51 UTC

Login to resync this repository