Kotlin is one of the fastest growing programming languages; it is used in the Android ecosystem and also is gaining traction in the enterprise world. So why not use Kotlin in the FaaS and Serverless space too?

Kotlin & Fn — A perfect combo?

Given its polyglot nature, Fn makes it very easy to write Kotlin based functions (“functions” as in FaaS).

Boostrap a Kotlin Function

To develop a Kotlin function, simply bootstrap it using the usual way with the Fn CLI (v0.4.129+), fn init —-runtime kotlin myfunc . This will create the required files to quickly get started. And obviously, all those files have a Kotlin flavor.

src/main/kotlin/HelloFunction.kt is a simple Kotlin function that helps you bootstrap your own function.

src/test/kotlin/HelloFunctionTest.kt is a Kotlin based rule to Unit test this same function.

A func.yaml containing the function metadata and a Maven based build file (pom.xml) are also created in that init process.

Test, Run and Deploy a Kotlin Function

To test the function, call Maven with the test goal mvn test .

To run the function, simply invoke fn run myfunc .

The function can be deployed via the usual way fn deploy --local --app myApp myfunc .