Liking cljdoc? Tell your friends :D

cljs-lambda.util


async-lambda-fncljs

(async-lambda-fn f & [{:keys [error-handler] :as opts}])

Repurpose the two-arg (event, context) asynchronous function f as a Lambda handler. The function's result determines the invocation's success at the Lambda level, without the requirement of using Lambda-specific (context/fail!, etc.) functionality within the body. Optional error handler behaves as handle-errors.

If the handler was passed a callback by the Lambda harness, that function will be used to signal completion, over the the context methods.

Success:

  • Returns successful Promesa/Bluebird promise
  • Returns core.async channel containing non-js/Error
  • Synchronously returns arbitrary object
(def ^:export wait
  (async-lambda-fn
   (fn [{n :msecs} ctx]
     (promesa/delay n :waited))))

Failure:

  • Returns rejected Promesa/Bluebird promise
  • Returns core.async channel containing js/Error
  • Synchronously throws js/Error
(def ^:export blow-up
  (async-lambda-fn
   (fn [_ ctx]
     (go
       (<! (async/timeout 10))
       (js/Error. "I blew up")))))

See macros/deflambda for an alternative approach to defining/export handler vars.

Repurpose the two-arg (event, context) asynchronous function `f` as a Lambda
  handler.  The function's result determines the invocation's success at the
  Lambda level, without the requirement of using
  Lambda-specific ([[context/fail!]], etc.) functionality within the body.
  Optional error handler behaves as [[handle-errors]].

  If the handler was passed a callback by the Lambda harness, that function will
  be used to signal completion, over the the context methods.

Success:

* Returns successful Promesa/Bluebird promise
* Returns `core.async` channel containing non-`js/Error`
* Synchronously returns arbitrary object

```clojure
(def ^:export wait
  (async-lambda-fn
   (fn [{n :msecs} ctx]
     (promesa/delay n :waited))))
```

Failure:

* Returns rejected Promesa/Bluebird promise
* Returns `core.async` channel containing `js/Error`
* Synchronously throws `js/Error`

```clojure
(def ^:export blow-up
  (async-lambda-fn
   (fn [_ ctx]
     (go
       (<! (async/timeout 10))
       (js/Error. "I blew up")))))
```

  See [[macros/deflambda]] for an alternative approach to defining/export
  handler vars.
sourceraw docstring

handle-errorscljs

(handle-errors f error-handler)

Returns a Lambda handler delegating to the input handler f, conveying any errors to error-handler, a function of [error event ctx], which has the opportunity to modify the eventual handler response (rethrow, return promise/channel, etc.)

(def ^:export successful-fn
  (-> (fn [event ctx] (p/rejected (js/Error.)))
      (handle-errors (fn [e event ctx] "Success"))
      async-lambda-fn))
Returns a Lambda handler delegating to the input handler `f`, conveying any
  errors to `error-handler`, a function of `[error event ctx]`, which has the
  opportunity to modify the eventual handler response (rethrow, return
  promise/channel, etc.)

```clojure
(def ^:export successful-fn
  (-> (fn [event ctx] (p/rejected (js/Error.)))
      (handle-errors (fn [e event ctx] "Success"))
      async-lambda-fn))
```
sourceraw docstring

wrap-lambda-fncljs

(wrap-lambda-fn f & [{parse-input? :parse-input? :or {parse-input? true}}])

Prepare a two-arg (event, context) function for exposure as a Lambda handler. The returned function will convert the event (Javascript Object) into a Clojurescript map with keyword keys, and turn the context into a record having keys :aws-request-id, :client-context, :log-group-name, :log-stream-name & :function-name - suitable for manipulation by context/done! etc.

Prepare a two-arg (event, context) function for exposure as a Lambda handler.
The returned function will convert the event (Javascript Object) into a
Clojurescript map with keyword keys, and turn the context into a record having
keys `:aws-request-id`, `:client-context`, `:log-group-name`,
`:log-stream-name` & `:function-name` - suitable for manipulation
by [[context/done!]]  etc.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close