Fork me on GitHub
#aws-lambda
<
2019-06-09
>
lloydshark07:06:17

Do have some code to show?

lloydshark07:06:03

If you are doing it from scratch then one way would be to...

lloydshark07:06:29

1. add gen-class to your target namespace definition. Say "my.lambda.handler"

lloydshark07:06:09

2. Call compile as part of your build. ie (compile 'my.lambda.handler)

lloydshark07:06:15

3. Make sure you package up the "compiled" handler from above into your artefact.

lloydshark07:06:46

Your handler name should be the package name.

lloydshark07:06:43

I used the same process when I had to create servlets for google app engine and I was only using tools deps so you can see an example of the above here.

johnjelinek19:06:15

I was able to figure this out by building my package with pack: https://github.com/juxt/pack.alpha

johnjelinek19:06:57

build my package:

# clojure -A:aot
# clojure -A:pack mach.pack.alpha.aws-lambda -C:aot lambda.zip

johnjelinek19:06:19

run it locally:

sam local invoke HelloWorldFunction --event event.json

johnjelinek19:06:32

spits out this:

2019-06-09 19:22:28 Invoking clj.core::handler (java8)
2019-06-09 19:22:29 Decompressing /root/code/clj/lambda.zip

Fetching lambci/lambda:java8 Docker container image......
2019-06-09 19:22:30 Mounting /tmp/tmp9_3_pwg7 as /var/task:ro,delegated inside runtime container
START RequestId: b8bb2ac0-d515-4f89-944c-fb2c15b40936 Version: $LATEST
END RequestId: b8bb2ac0-d515-4f89-944c-fb2c15b40936
REPORT RequestId: b8bb2ac0-d515-4f89-944c-fb2c15b40936  Duration: 15.93 ms      Billed Duration: 100 ms Memory Size: 128 MB     Max Memory Used: 8 MB

"Hello World!"

johnjelinek19:06:52

code looks like this:

(ns clj.core
  (:gen-class
   :methods [^:static [handler [] String]]))

(defn -handler []
  (str "Hello World!"))

lvh22:06:59

I'm using pack and it works 🙂

👍 1
lvh22:06:36

has anyone had any luck locally emulating alb's lambda integration? sam supports apigw, but that's different (no (proxy+), you always get the entire path)