This repository hosts an SDK for developing Lambda functions for the Manetu Platform in the ClojureScript programming language.
The Manetu platform serves Lambda functions within a WebAssembly (WASM) environment. We can leverage the Clojurescript language in our Lambda functions using a combination of two tools: shadow-cljs to compile Clojurescript to an ECMAScript Module (ESM), followed by mjsc to compile ESM to WASM.
mkdir my-lambda
cd my-lambda
{:builds {:lambda {:target :esm
:output-dir "target"
:runtime :custom
:modules {:lambda {:init-fn hellocljs.core/main}}}}
:lein true}
(defproject hellocljs "0.0.1-SNAPSHOT"
:min-lein-version "2.9.0"
:dependencies [[org.clojure/clojure "1.11.2"]
[org.clojure/clojurescript "1.11.132"
:exclusions [com.google.javascript/closure-compiler-unshaded
org.clojure/google-closure-library]]
[io.github.manetu/lambda-sdk "0.0.1-SNAPSHOT"]
[thheller/shadow-cljs "2.27.1"]]
:source-paths ["src"])
OBJECT=target/lambda.wasm
SRCS = $(shell find src -type f)
all: $(OBJECT)
target:
mkdir target
target/lambda.js: Makefile project.clj shadow-cljs.edn $(SRCS)
shadow-cljs release lambda
$(OBJECT): target/lambda.js
mjsc compile $^ -o $@
clean:
-rm -rf target
mkdir -p src/hellocljs
pushd src/hellocljs
(ns hellocljs.core
(:require [manetu.lambda :as lambda]))
(defn handle-request [{{:keys [name]} :params}]
{:status 200
:body (str "Hello, " name)})
(defn main []
(lambda/register-handler handle-request)
(println "Module Initialized"))
popd
make
You should now have a file 'target/lambda.wasm' ready for deployment.
We can leverage any OCI registry to publish our Lambda function using the wasm-to-oci tool.
$ wasm-to-oci push target/lambda.wasm my-registry.example.com/my-lambda:v0.0.1
INFO[0003] Pushed: my-registry.example.com/my-lambda:v0.0.1
INFO[0003] Size: 1242738
INFO[0003] Digest: sha256:cf9040f3bcd0e84232013ada2b3af02fe3799859480046b88cdd03b59987f3c9
Create a file 'site.yml' with the following contents:
api-version: lambda.manetu.io/v1alpha1
kind: Site
metadata:
name: hello
spec:
runtime: wasi.1.alpha2
image: oci://my-registry.example.com/my-lambda:v0.0.1
env:
LOG_LEVEL: trace
triggers:
http-queries:
- route: /greet
summary: "Returns a greeting to the user"
description: "This request allows you to test the ability to deploy and invoke a simple lambda function."
query-parameters:
- name: "name"
schema: { type: "string" }
description: "The caller's name"
responses:
200:
description: "computed greeting"
content:
text/plain:
schema:
type: string
Be sure to adjust the image OCI URL.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close