Coder Social home page Coder Social logo

jbarnet / cljs-lambda-nervous-io Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nervous-systems/cljs-lambda

0.0 0.0 0.0 145 KB

Utilities around deploying Clojurescript functions to AWS Lambda

License: The Unlicense

CSS 2.37% Clojure 90.28% JavaScript 1.03% HTML 1.32% Shell 5.00%

cljs-lambda-nervous-io's Introduction

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

Benefits

  • Low instance warmup penalty
  • Ability to specify execution roles and resource limits in project definition
  • Use promises, or asynchronous channels for deferred completion
  • :optimizations :advanced support, for smaller zip files*
  • Utilities for testing Lambda entrypoints off of EC2
  • Parallel deployments
  • Function publishing/versioning

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

Clojars Project

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

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.

cljs-lambda-nervous-io's People

Contributors

moea avatar dheidebrecht avatar honzabrecka avatar zrzka avatar aleksandersumowski avatar bhagany avatar jetmind avatar vikeri avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.