• This repository has been archived on 22/Oct/2022
  • Stars
    star
    311
  • Rank 130,336 (Top 3 %)
  • Language
    Clojure
  • License
    The Unlicense
  • Created almost 9 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Utilities around deploying Clojurescript functions to AWS Lambda

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
### 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

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.

More Repositories

1

ffmpeg-opengl

Filter for applying GLSL shaders to movies via ffmpeg
C
124
star
2

sputter

Ethereum Virtual Machine (EVM) implementation
Clojure
120
star
3

eulalie

Asynchronous AWS client for Clojure & Clojurescript/Node
Clojure
86
star
4

serverless-cljs-plugin

Serverless plugin for Clojurescript deployment w/ cljs-lambda
JavaScript
73
star
5

kvlt

Multi-target Clojure/script HTTP client
Clojure
69
star
6

hildebrand

Asynchronous DynamoDB client for Clojure & Clojurescript/Node
Clojure
66
star
7

fink-nottle

Asynchronous Clojure/Clojurescript client for Amazon's SNS & SQS services
Clojure
48
star
8

java-unsigned-integers

Optimized, immutable Java implementations of fixed-width, unsigned integers.
Java
31
star
9

chemtrack-example

Clojurescript/Node/Reagent/Lambda Example Application
Clojure
17
star
10

cljs-nodejs-externs

Packaged externs for the Node.js standard library + utilities
Clojure
12
star
11

balonius

Clojure/script Poloniex (cryptocurrency exchange) client
Clojure
11
star
12

cljs-rollbar

Clojurescript/Node-friendly Rollbar client
Clojure
10
star
13

youtube-eliza

Answering the hard questions w/ Clojurescript, AWS Lambda & Slack
Clojure
8
star
14

sns-beanstalk-chat

Clojure
7
star
15

iris-examples

Clojure Iris examples
Clojure
5
star
16

shapeshiftr

Clojure/script shapeshift.io client
Clojure
5
star
17

promesa-check

Utilities for running asynchronous test.check trials
Clojure
4
star
18

cljs-lambda-slack-command

Clojure
2
star
19

aws-polling-task-scheduler

Clojure
2
star
20

glossop

Clojure
1
star
21

fink-nottle-demo

Clojure
1
star
22

thelema

Clojurescript/AWS Mixtape-creating application
Clojure
1
star