aws-lambda

lloydshark 2019-06-09T07:43:17.002100Z

Do have some code to show?

lloydshark 2019-06-09T07:48:03.003900Z

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

lloydshark 2019-06-09T07:48:29.004200Z

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

lloydshark 2019-06-09T07:49:09.004700Z

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

lloydshark 2019-06-09T07:50:15.005800Z

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

lloydshark 2019-06-09T07:50:46.006300Z

Your handler name should be the package name.

lloydshark 2019-06-09T07:53:43.008Z

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.

lloydshark 2019-06-09T07:54:01.008300Z

https://github.com/lloydshark/google-app-engine-clojure

johnjelinek 2019-06-09T19:23:15.009500Z

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

johnjelinek 2019-06-09T19:23:57.009700Z

build my package:

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

johnjelinek 2019-06-09T19:24:19.009900Z

run it locally:

sam local invoke HelloWorldFunction --event event.json

johnjelinek 2019-06-09T19:24:32.010100Z

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!"

johnjelinek 2019-06-09T19:24:52.010300Z

code looks like this:

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

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

lvh 2019-06-09T22:31:59.010600Z

I'm using pack and it works 🙂

👍 1
lvh 2019-06-09T22:32:36.011300Z

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)