• Stars
    star
    1,124
  • Rank 39,753 (Top 0.9 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created almost 5 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Kotlin Serverless Framework

Kotless Icon Kotless

JetBrains incubator project KotlinLang slack

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!

Kotless consists of two main parts:

  • DSL provides a way of defining serverless applications. There are three DSLs supported:
    • Kotless DSL โ€” Kotless own DSL that provides annotations to declare routing, scheduled events, etc.
    • Ktor โ€” Ktor engine that is introspected by Kotless. Use standard Ktor syntax and Kotless will generate deployment.
    • Spring Boot โ€” Spring Boot serverless container that is introspected by Kotless. Use standard Spring syntax and Kotless will generate deployment.
  • Kotless Gradle Plugin provides a way of deploying serverless application. For that, it:
    • performs the tasks of generating Terraform code from the application code and, subsequently, deploying it to AWS or Azure;
    • runs application locally, emulates the AWS environment (if necessary) and provides the possibility for IDE debugging.

One of the key features of Kotless is its ability to embed into existing applications. Kotless makes super easy deployment of existing Spring and Ktor applications to AWS and Microsoft Azure serverless platforms.

Getting started

Setting up project

Kotless uses Gradle to wrap around the existing building process and insert the deployment into it.

Consider using one of the latest versions of Gradle, starting with the 7.2 version.

Basically, if you already use Gradle, you only need to do two things.

Firstly, set up the Kotless Gradle plugin.

You will have to tell Gradle where to find the plugin by editing settings.gradle.kts:

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()
    }
}

And 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")
}

Please note that if you use Ktor or Spring Boot you will need to replace existing in your project dependency with a special Kotless *-lang dependency. Also, after that you will need to align version of dependent libraries (like Spring Security) with version bundled in *-lang (see this paragraph)

This gives you access to DSL interfaces in your code and sets up a Lambda dispatcher inside your application.

Deploying to the cloud

Depending on a use case, you may want to deploy application either in an AWS or Microsoft Azure.

Note, that if you even don't have a cloud account, you can still use Kotless locally to run and debug your application -- just use local Gradle task.

Deploying to AWS

If you don't have an AWS account, you can create it following simple instruction by Hadi Hariri.

If you have an AWS account and want to perform the real deployment โ€” let's set up everything for it! It's rather simple:

kotless {
    config {

        aws {
            storage {
                bucket = "kotless.s3.example.com"
            }

            profile = "example"
            region = "eu-west-1"
        }
    }

    webapp {
        dns("kotless", "example.com")
    }
}

Here we set up the config of Kotless itself:

  • the bucket, which will be used to store lambdas and configs;
  • Terraform configuration with the name of the profile to access AWS.

Then we set up a specific application to deploy:

  • Route53 alias for the resulting application (you need to pre-create an ACM certificate for the DNS record).

And that's the whole setup!

Deploying to Azure

Deployment to Microsoft Azure is also pretty straightforward and simple:

kotless {
    config {
        azure {
            storage {
                storageAccount = "your-storage-account"
                container = "container-which-kotless-would-use"
            }

            terraform {
                backend {
                    resourceGroup = "your-resource-group"
                }
            }
        }
    }

    webapp {
        dns("kotless", "example.com")
    }
}

Here we set up the config of Kotless itself:

  • the storage, which will be used to store lambdas and configs;
  • Terraform configuration with the name of the profile to access Azure.

Then we set up a specific application to deploy:

  • Azure DNS alias for the resulting application (you need to pre-create certificate for the DNS record).

And that's the whole setup!

Creating application

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!"
}

Local start

Kotless-based applications can start locally as an HTTP server. This functionality is supported by all DSLs.

Moreover, Kotless local start may spin up an AWS emulation (docker required). Just instantiate your AWS service client using override for Kotless local starts:

val client = AmazonDynamoDBClientBuilder.standard().withKotlessLocal(AwsResource.DynamoDB).build()

And enable it in Gradle:

kotless {
    //<...>
    extensions {
        local {
            //enables AWS emulation (disabled by default)
            useAWSEmulation = true
        }
    }
}

During the local run, LocalStack will be started and all clients will be pointed to its endpoint automatically.

Local start functionality does not require any access to cloud provider, so you may check how your application behaves without an AWS account. Also, it gives you the possibility to debug your application locally from your IDE.

Integration with existing applications

Kotless is able to deploy existing Spring Boot or Ktor application to AWS serverless platform. To do it, you'll need to set up a plugin and replace existing dependency with the appropriate Kotless DSL.

For Ktor, you should replace existing engine ( e.g. implementation("io.ktor", "ktor-server-netty", "1.5.0")) with implementation("io.kotless", "ktor-lang", "0.1.6"). Note that this dependency bundles Ktor of version 1.5.0, so you may need to upgrade other Ktor libraries (like ktor-html-builder) to this version.

For Spring Boot you should replace the starter you use ( e.g. implementation("org.springframework.boot", "spring-boot-starter-web", "2.3.0.RELASE)) with implementation("io.kotless", "spring-boot-lang", "0.1.6"). Note that this dependency bundles Spring Boot of version 2.4.2, so you also may need to upgrade other Spring Boot libraries to this version.

Once it is done, you may hit deploy task and make your application serverless. Note, that you will still be able to run application locally via local Gradle task.

Advanced features

While Kotless can be used as a framework for the rapid creation of serverless applications, it has many more features covering different areas of application.

Including, but not limited to:

  • Lambdas auto-warming โ€” Kotless creates schedulers to execute warming sequences to never leave your lambdas cold. As a result, applications under moderate load are not vulnerable to cold-start problem.
  • Permissions management โ€” you can declare which permissions to which AWS resources are required for application via annotations on Kotlin functions, classes or objects. Permissions will be granted automatically.
  • Static resources โ€” Kotless will deploy static resources to S3 and set up CDN for them. It may greatly improve the response time of your application and is supported by all DSLs.
  • Scheduled events โ€” Kotless sets up timers to execute @Scheduled jobs on schedule;
  • Terraform extensions โ€” Kotless-generated code can be extended by custom Terraform code;

Kotless is in active development, so we are currently working on extending this list with such features as:

  • Support of other clouds โ€” Kotless is based on a cloud-agnostic schema, so we are working on support of other clouds.
  • Support of multiplatform applications โ€” Kotless will not use any platform-specific libraries to give you a choice of a Lambda runtime (JVM/JS/Native).
  • Versioned deployment โ€” Kotless will be able to deploy several versions of the application and maintain one of them as active.
  • Implicit permissions granting โ€” Kotless will be able to deduce permissions from AWS SDK function calls.
  • Events handlers support โ€” Kotless will generate events subscriptions for properly annotated events handlers.

Examples

Any explanation becomes much better with a proper example.

In the repository's examples folder, you can find example projects built with Kotless DSL:

  • kotless/site โ€” a site about Kotless written with Kotless DSL (site.kotless.io). This example demonstrates @StaticGet and @Get (static and dynamic routes) usage, as well as Link API.
  • kotless/shortener โ€” a simple URL shortener written with Kotless DSL (short.kotless.io). This example demonstrates @Get ( dynamic routes), @Scheduled (scheduled lambdas), Permissions API (for DynamoDB access), and Terraform extensions.

Similar examples exist for Ktor:

  • ktor/site โ€” a site about Kotless written with Ktor (ktor.site.kotless.io). This example demonstrates static {...} and routing {...} usage.
  • ktor/shortener โ€” a simple URL shortener written with Ktor (ktor.short.kotless.io). This example demonstrates routing { ... } (dynamic routes), Permissions API (for DynamoDB access), and Terraform extensions.

And for Spring Boot:

  • spring/site โ€” a site about Kotless written with Spring Boot (spring.site.kotless.io). This example demonstrates usage of statics and @RestController.
  • spring/shortener โ€” a simple URL shortener written with Spring Boot (spring.short.kotless.io). This example demonstrates usage of @RestController (dynamic routes), Permissions API (for DynamoDB access), and Terraform extensions.

Want to know more?

You may take a look at Wiki where the client documentation on Kotless is located.

Apart from that, the Kotless code itself is widely documented, and you can take a look into its interfaces to get to know Kotless better.

You may ask questions and participate in discussions on #kotless channel in KotlinLang slack.

Acknowledgements

Special thanks to:

  • Alexandra Pavlova (aka sunalex) for our beautiful logo;
  • Yaroslav Golubev for help with documentation;
  • Gregor Billing for help with the Gradle plugin and more.

More Repositories

1

kotlin

The Kotlin Programming Language.
Kotlin
45,725
star
2

intellij-community

IntelliJ IDEA Community Edition & IntelliJ Platform
16,452
star
3

compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
Kotlin
14,677
star
4

JetBrainsMono

JetBrains Mono โ€“ the free and open-source typeface for developers
Shell
10,126
star
5

ideavim

IdeaVim โ€“ A Vim engine for JetBrains IDEs
Kotlin
7,980
star
6

Exposed

Kotlin SQL Framework
Kotlin
7,869
star
7

kotlin-native

Kotlin/Native infrastructure
Kotlin
7,048
star
8

ring-ui

A collection of JetBrains Web UI components
TypeScript
3,555
star
9

kotlinconf-app

KotlinConf Schedule Application
Kotlin
2,834
star
10

intellij-platform-plugin-template

Template repository for creating plugins for IntelliJ Platform
Kotlin
2,791
star
11

skija

Java bindings for Skia
Java
2,605
star
12

create-react-kotlin-app

Create React apps using Kotlin with no build configuration
JavaScript
2,477
star
13

projector-docker

Run JetBrains IDEs remotely with Docker
Shell
2,209
star
14

intellij-plugins

Open-source plugins included in the distribution of IntelliJ IDEA Ultimate and other IDEs based on the IntelliJ Platform
Java
2,002
star
15

svg-sprite-loader

Webpack loader for creating SVG sprites.
JavaScript
1,998
star
16

skiko

Kotlin MPP bindings to Skia
C++
1,685
star
17

compose-multiplatform-ios-android-template

Compose Multiplatform iOS+Android Application project template
Kotlin
1,563
star
18

MPS

JetBrains Meta programming System
JetBrains MPS
1,500
star
19

lets-plot

Multiplatform plotting library based on the Grammar of Graphics
Kotlin
1,446
star
20

kotlin-web-site

The Kotlin programming language website
JavaScript
1,413
star
21

intellij-platform-gradle-plugin

Gradle plugin for building plugins for IntelliJ-based IDEs
Kotlin
1,377
star
22

phpstorm-stubs

PHP runtime & extensions header files for PhpStorm
PHP
1,297
star
23

kotlin-wrappers

Kotlin wrappers for popular JavaScript libraries
Kotlin
1,294
star
24

idea-gitignore

.ignore support plugin for IntelliJ IDEA
Kotlin
1,287
star
25

projector-server

Server-side library for running Swing applications remotely
Kotlin
1,230
star
26

resharper-unity

Unity support for both ReSharper and Rider
C#
1,199
star
27

intellij-sdk-docs

IntelliJ SDK Platform Documentation
Markdown
1,181
star
28

xodus

Transactional schema-less embedded database used by JetBrains YouTrack and JetBrains Hub.
Java
1,155
star
29

intellij-scala

Scala plugin for IntelliJ IDEA
Scala
1,137
star
30

JetBrainsRuntime

Runtime environment based on OpenJDK for running IntelliJ Platform-based products on Windows, macOS, and Linux
Java
1,118
star
31

intellij-sdk-code-samples

Mirror of the IntelliJ SDK Docs Code Samples
Java
980
star
32

js-graphql-intellij-plugin

GraphQL language support for WebStorm, IntelliJ IDEA and other IDEs based on the IntelliJ Platform.
Java
879
star
33

android

Android Plugin for IntelliJ IDEA. This repository is a subset of https://git.jetbrains.org/?p=idea/android.git cut according to GitHub file size limitations.
Kotlin
863
star
34

projector-client

Common and client-related code for running Swing applications remotely
Kotlin
813
star
35

projector-installer

Install, configure and run JetBrains IDEs with Projector Server on Linux or in WSL
Python
810
star
36

Grammar-Kit

Grammar files support & parser/PSI generation for IntelliJ IDEA
Java
688
star
37

Arend

The Arend Proof Assistant
Java
676
star
38

amper

Amper - a build and project configuration tool with a focus on the user experience and the IDE support
Kotlin
621
star
39

markdown

Markdown parser written in kotlin
Kotlin
617
star
40

jediterm

Pure Java Terminal Emulator. Works with SSH and PTY.
Java
611
star
41

compose-multiplatform-template

Compose Multiplatform Application project template
Kotlin
603
star
42

jewel

An implementation of the IntelliJ look and feels in Compose for Desktop
Kotlin
580
star
43

Nitra

Public Nitra repository
Nemerle
549
star
44

lincheck

Framework for testing concurrent data structures
Kotlin
520
star
45

intellij-micropython

Plugin for MicroPython devices in PyCharm and IntelliJ
Python
482
star
46

kotlin-playground

Self-contained component to embed in websites for running Kotlin code
JavaScript
422
star
47

colorSchemeTool

Python
396
star
48

compose-multiplatform-desktop-template

Compose Multiplatform Desktop Application project template
Kotlin
393
star
49

lets-plot-kotlin

Grammar of Graphics for Kotlin
Kotlin
389
star
50

Qodana

๐Ÿ“ Source repository of Qodana Help
388
star
51

rd

Reactive Distributed communication framework for .NET, Kotlin, C++. Inspired by Rider IDE.
C#
373
star
52

java-annotations

Annotations for JVM-based languages.
Java
362
star
53

phpstorm-attributes

PhpStorm specific attributes
PHP
357
star
54

Unity3dRider

Unity JetBrains Rider integration
348
star
55

godot-support

C#
339
star
56

pty4j

Pty for Java
Java
338
star
57

resharper-fsharp

F# support in JetBrains Rider
F#
320
star
58

phpstorm-workshop

Code for the PhpStorm workshop
PHP
287
star
59

awesome-pycharm

A curated list of resources for learning and using PyCharm, a Python IDE from JetBrains
271
star
60

web-types

JSON standard for documenting web component libraries for IDEs, documentation generators and other tools
TypeScript
270
star
61

meta-runner-power-pack

A set of Meta-runners for TeamCity
PowerShell
256
star
62

inspection-plugin

Gradle plugin to launch IDEA inspections
Kotlin
255
star
63

youtrack-mobile

A iOS and Android client for YouTrack
TypeScript
255
star
64

gradle-changelog-plugin

Plugin for parsing and managing the Changelog in a "keep a changelog" style.
Kotlin
252
star
65

ideolog

Interactive viewer for '.log' files.
Kotlin
250
star
66

qodana-action

โš™๏ธ Scan your Go, Java, Kotlin, PHP, Python, JavaScript, TypeScript, .NET projects at GitHub with Qodana. This repository contains Qodana for Azure, GitHub, CircleCI and Gradle
JavaScript
234
star
67

gradle-idea-ext-plugin

Plugin to store IJ settings in gradle script
Groovy
227
star
68

php-timeline

Notable events of PHP history
222
star
69

resharper-rider-samples

Simple interactive exercises to help learn ReSharper and Rider
C#
221
star
70

la-clojure

Clojure plugin for IntelliJ IDEA
Java
220
star
71

kotlin-compiler-server

Server for executing kotlin code
Kotlin
216
star
72

jdk8u_jdk

Java
210
star
73

jcef

A simple framework for embedding Chromium-based browsers into Java-based applications.
Java
206
star
74

pest-intellij

The official Pest Plugin for PhpStorm / IntelliJ IDEA
Kotlin
195
star
75

youtrack-workflows

YouTrack Custom Workflow Repository
JavaScript
194
star
76

psiviewer

PSI Viewer for IntelliJ IDEA plugin development
Java
175
star
77

svg-mixer

Node.js toolset for generating & transforming SVG images and sprites in modern way
JavaScript
173
star
78

compose-for-web-demos

Historical repository of early Compose for Web effort.
171
star
79

phpstorm-docker-images

Pre-configured Docker images used by PhpStorm team
Dockerfile
170
star
80

rider-efcore

Entity Framework Core UI plugin for JetBrains Rider
Kotlin
169
star
81

jetbrains_guide

JetBrains Guides where Developer Advocacy and the community share ideas.
CSS
168
star
82

kotlin-web-demo

Online mini-IDE for Kotlin
Kotlin
168
star
83

intellij-plugin-verifier

Compatibility verification tool for IntelliJ Platform plugins
Kotlin
165
star
84

intellij-samples

Code that demonstrates various IntelliJ IDEA features
Java
163
star
85

jdk8u_hotspot

C++
159
star
86

resharper-rider-plugin

https://www.jetbrains.com/help/resharper/sdk/
PowerShell
158
star
87

qodana-cli

๐Ÿ”ง JetBrains Qodanaโ€™s official command line tool
Go
154
star
88

teamcity-messages

Python Unit Test Reporting to TeamCity
Python
139
star
89

ruby-type-inference

Dynamic definitions and types provider for ruby static analysis
Kotlin
136
star
90

educational-plugin

Educational plugin to learn and teach programming languages such as Kotlin, Java, Python, JavaScript, and others right inside of JetBrains IntelliJ Platform based IDEs.
Kotlin
134
star
91

resharper-angularjs

ReSharper plugin for AngularJS support
JavaScript
134
star
92

clion-remote

134
star
93

golandtipsandtricks

This is an ever evolving repository for GoLand Tips&Tricks
Go
132
star
94

python-skeletons

The python-skeltons repo is deprecated: use PEP 484 and Typeshed instead
Python
132
star
95

clion-wsl

Shell
130
star
96

phpstorm-phpstan-plugin

PHPStan plugin for PhpStorm
Java
130
star
97

teamcity-docker-samples

TeamCity docker compose samples
Shell
128
star
98

phpstorm-psalm-plugin

Psalm plugin for PhpStorm
Java
126
star
99

jdk8u

Shell
123
star
100

YouTrackSharp

.NET Standard 2.0 Library to access YouTrack API.
C#
123
star