Kotless

Kotless

Language
Kotlin
Category
4
Version
0.20.0
Authors
JetBrains
Description
Kotless stands for Kotlin serverless framework. Its focus lies in reducing the routine of serverless deployment creation by generating it straight from the code of the application itself. So, simply speaking, Kotless gives you one magic button to deploy your Web application as a serverless application on AWS and Azure!
Install Instructions
  • Using Gradle, you need to tell it where to find the plugin by editing settings.gradle.kts
// [settings.gradle.kts file]
pluginManagement {
resolutionStrategy {
this.eachPlugin {
if (requested.id.id == "io.kotless") {
useModule("io.kotless:gradle:${this.requested.version}")
}
}
}
repositories {
maven(url = uri("https://packages.jetbrains.team/maven/p/ktls/maven"))
gradlePluginPortal()
mavenCentral()
}
}
  • Now apply the plugin:
//Imports are necessary, for this example
import io.kotless.plugin.gradle.dsl.Webapp.Route53
import io.kotless.plugin.gradle.dsl.kotless
//Group may be used by Kotless DSL to reduce the number of introspected classes by package
//So, don't forget to set it
group = "org.example"
version = "0.1.0"
plugins {
//Version of Kotlin should be 1.3.72+
kotlin("jvm") version "1.5.31" apply true
id("io.kotless") version "0.2.0" apply true
}
  • Secondly, add Kotless DSL (or Ktor or Spring Boot) as a library to your application:
repositories {
mavenCentral()
//Kotless repository
maven(url = uri("https://packages.jetbrains.team/maven/p/ktls/maven"))
}
dependencies {
implementation("io.kotless", "kotless-lang", "0.2.0")
implementation("io.kotless", "kotless-lang-aws", "0.2.0")
// if you want to deploy to Microsoft Azure, just replace -aws with -azure
// implementation("io.kotless", "ktor-lang-azure", "0.2.0")
//or for Ktor (Note, that `ktor-lang` depends on Ktor version 1.5.0)
//implementation("io.kotless", "ktor-lang", "0.2.0")
//implementation("io.kotless", "ktor-lang-aws", "0.2.0")
//implementation("io.kotless", "ktor-lang-azure", "0.2.0")
//or for Spring Boot (Note, that `spring-boot-lang` depends on Spring Boot version 2.3.0.RELEASE)
//implementation("io.kotless", "spring-boot-lang", "0.2.0")
//implementation("io.kotless", "spring-boot-lang-aws", "0.2.0")
//implementation("io.kotless", "spring-boot-lang-azure", "0.2.0")
}
Usage
  • Now you can create your first serverless application with Kotless DSL:
@Get("/")
fun main() = "Hello world!"
  • Or with Ktor:
class Server : Kotless() {
override fun prepare(app: Application) {
app.routing {
get("/") {
call.respondText { "Hello World!" }
}
}
}
}
  • Or with Spring Boot:
@SpringBootApplication
open class Application : Kotless() {
override val bootKlass: KClass<*> = this::class
}
@RestController
object Pages {
@GetMapping("/")
fun main() = "Hello World!"
}
Links