Skip to content

Commit f058244

Browse files
committed
feat: add basic lambda function
1 parent 1407f48 commit f058244

File tree

5 files changed

+53
-0
lines changed

5 files changed

+53
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.clj-kondo/
2+
.lsp/
3+
.cpcache/
4+
target/
5+
.DS_Store

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Basic JVM Clojure lambda setup
2+
3+
## Build
4+
5+
To build an uberjar:
6+
7+
```bash
8+
$ clj -T:build uber
9+
```
10+
11+
Then upload the `target/lambda-*.jar` to your [lambda function](https://docs.aws.amazon.com/lambda/latest/dg/java-package.html#java-package-console)
12+
and off you go!

build.clj

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
(ns build
2+
(:require [clojure.tools.build.api :as b]))
3+
4+
(def lib 'my/lambda)
5+
(def version (format "0.1.%s" (b/git-count-revs nil)))
6+
(def class-dir "target/classes")
7+
(def basis (delay (b/create-basis {:project "deps.edn"})))
8+
(def uber-file (format "target/%s-%s-standalone.jar" (name lib) version))
9+
10+
(defn clean [_]
11+
(b/delete {:path "target"}))
12+
13+
(defn uber [_]
14+
(b/copy-dir {:src-dirs ["src" "resources"]
15+
:target-dir class-dir})
16+
(b/compile-clj {:basis @basis
17+
:src-dirs ["src"]
18+
:class-dir class-dir})
19+
(b/uber {:class-dir class-dir
20+
:uber-file uber-file
21+
:basis @basis}))

deps.edn

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{:paths ["src"]
2+
:deps {org.clojure/clojure {:mvn/version "1.11.1"}
3+
com.amazonaws/aws-lambda-java-core {:mvn/version "1.2.3"}}
4+
:aliases
5+
{:build {:extra-deps {io.github.clojure/tools.build {:git/tag "v0.8.4" :git/sha "8c3cd69"}}
6+
:ns-default build}}}

src/lambda.clj

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(ns lambda
2+
(:gen-class
3+
:implements [com.amazonaws.services.lambda.runtime.RequestStreamHandler]))
4+
5+
(defn -handleRequest [_ is os _context]
6+
(let [input (slurp is)]
7+
(if (re-find #"error" input)
8+
(throw (ex-info "test" {:my "error"}))
9+
(spit os "test"))))

0 commit comments

Comments
 (0)