This is a small example illustrating this blog post about doing Serverless functions in Native Kotlin.
This is a followup of the previous version that was running in the JVM.
You need to have OpenWhisk up and running, then you could create the action to OpenWhisk with:
$ wsk action create native-fibonacci --docker jamedina/kotlin-native-fibonacciTo test the new action just run:
$ wsk action invoke --result native-fibonacci --param numbers 5This will output something like:
{
"result": [
1,
1,
2,
3,
5
]
}If you like to run your acction there is an script to create the docker and upload it to docker hub, you need to modify.
You could use this base image to build your own kotlin native serverless functions, follow this Dockerfile to understand how.
If you want to run the function locally first install kotlin native:
git clone --depth 1 https://github.com/JetBrains/kotlin-native.git /kotlin-native
cd /kotlin-native
./gradlew dependencies:update
./gradlew dist
export PATH="$PATH:/kotlin-native/dist/bin"Then you could build, from this repository
gradlew buildThen to run the action
./build/konan/bin/Fibonacci.kexe "{ \"numbers\" : 5 }"This will output something like:
{"result":[1,1,2,3,5]}