Skip to content

Instantly share code, notes, and snippets.

@igrishaev
Created May 2, 2025 09:18
Show Gist options
  • Select an option

  • Save igrishaev/c066879cc0d2ba69a6c1485399d17bfd to your computer and use it in GitHub Desktop.

Select an option

Save igrishaev/c066879cc0d2ba69a6c1485399d17bfd to your computer and use it in GitHub Desktop.
;; https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html
;; https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html
;; https://docs.aws.amazon.com/lambda/latest/dg/urls-invocation.html
(ns lambda.main
(:require
[lambda.log :as log]
[lambda.api :as api]
[lambda.error :as e])
(:import
(java.util.function Function
Supplier)
(java.util.concurrent CompletableFuture)
(java.util.concurrent Executors)))
(set! *warn-on-reflection* true)
(defmacro supplier [& body]
`(reify Supplier
(get [this#]
~@body)))
(defmacro function [[bind] & body]
`(reify Function
(apply [this# ~bind]
~@body)))
(future
...s.df.sfd.
)
(then [x]
sfsdfsdf)
(error [xcs]
sdfsdf)
(let [a dsd
b fsdf
c sdfds]
)
(f/let [a sdf
b sdfsdf]
(+ a b))
(then [sdfs]
sdfsd)
(error [e]
sdfsdf)
(let [__a (future)
__b (future...)
a (deref __a)
b (deref __b)]
())
(let [futs (into-array ....)]
(-> (CompletableFuture/allOf futs)
(.allOf)
(.thenApplyAsync
(fn [_]
(mapv deref futs)))))
(loop [i 0]
)
(fn []
(let [fut
(CompletableFuture/supplyAsync
...)
(if (recur? fut)
(recur fut)
fut)
]
)
)
(defn run [fn-event]
(while true
(let [{:keys [headers body]}
(api/next-invocation)
request-id
(get headers :lambda-runtime-aws-request-id)]
(-> (CompletableFuture/supplyAsync
(supplier
(fn-event body)))
(.thenApplyAsync
(function [response]
(api/invocation-response request-id response)))
(.exceptionally
(function [e]
(log/errorf "Event error, request ID: %s" request-id)
(log/exception e)
(api/invocation-error request-id e))))))
#_
(let [executor
(Executors/newFixedThreadPool 4)]
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment