Kotlin/Native AWS Lambda


I’m new to Kotlin/Native and I wanted to explore it as a replacement for Kotlin/JVM for AWS Lambda. Before I dig to deep I wanted to make sure that Kotlin/Native supports my use cases of networking clients and database drivers.

I have been looking at Ktor Client for networking. I see support for iOS, but not support for Linux. Does anybody know reference that point to examples? Are there any other network clients for Linux?

As for database, I haven’t found anything. I was think this could be done with C database drivers with a Kotlin/C interop. Is this a good approach or are there database drivers for Kotlin that I’m not seeing?

I would love to see the Kotlin/Native team solve these problems. I think it would make Kotlin an exciting alternative to GoLang. If I could get pointed in the correct direction, I might be able to help some.

Jeffrey Kleiss

1 Like


Hey Jeffrey,

I want to preface this response by stating that Kotlin/Native is currently in beta status. Keep that in mind before you use it in production because I believe the Kotlin team is still trying to work things out with it, especially speed improvements with the standard library.

Now, on to your question. The Ktor client is built on top of Kotlin Multiplatform, and according to the release notes for Ktor 1.1.2 the client now works on Kotlin Native using libcurl in the background.

I don’t know of any Kotlin Native database drivers, but I’m sure if there’s a native library for the driver in question you can just do interop with it assuming you point the Kotlin Native compiler at the right header files and native libraries.

Kotlin Native should be pretty easy to use and has a lot of nice features like the memScoped block, which will automatically clean up any dynamic memory you allocate within it at the end of the block. I think once it matures more it will be a great alternative to golang, especially once the Kotlin Native coroutines API gets fully stable.

Hope that helps!



I would also point out that developing in Kotlin Native may not be as free as using it on the JVM or Javascript. There are free versions of IntelliJ that will let you build and debug. If you want to debug Kotlin Native, the only tool for doing so is CLion, which has no free version.



Since Amazon announced custom runtimes it is possible to use K/N for AWS Lambda.

Take a look at an example AWS Lambda authored in K/N here. To understand how custom runtimes work, take a look at this tutorial.

As of March 2019 using K/N for Lambdas has, IMHO, more cons than cons:

  • The interaction between custom runtime and your code is done via REST API that is way less convenient than using language SDKs.
  • You cannot use other AWS APIs via SDKs, only via REST APU
  • Lack of libraries in general: you’ll need to use cinterop literally for every library you want to use!

Right now it seems that Golang is a better alternative for low-footprint Lambdas.

Answering your questions:

Does anybody know reference that point to examples?

See the example above.

Are there any other network clients for Linux?

As of 1.1.2 Ktor supports cURL. The example uses this API.

this could be done with C database drivers with a Kotlin/C interop.

AFAIK, that’s the only option for now.



I’ve wrote an article about simple K/N AWS Lambda function here.

1 Like