33
Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

  • Upload
    others

  • View
    35

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

Kotlin 1.4 Online Event

October 15, 2020@vdtankov

KotlessKotlin ServerlessFrameworkVladislav Tankov

Page 2: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

Introductionto serverlessA few words on the hottest topic

Page 3: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

Serverless is

a cloud-computing execution model in which the cloud provider runsthe server and dynamically manages the allocation of machine resourcesWikipedia

Page 4: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

Basically, it means

1. Take small elements – stateless functions

2. Combine them with events to make an application

3. Run the application in the cloud

Page 5: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

Async

Use

Sync

Rest API/b

/a

/b

/a

Page 6: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

Why?

Page 7: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

Pros of serverless

● Pay per request

● Scale up to thousands of CPUs

● Fault-tolerant

Page 8: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

No cons?

Page 9: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

### API route: GET /longvariable "_long_envvars" { type = "map" default = { KOTLESS_PACKAGES = "kotless" }}

resource "aws_lambda_function" "_long" { function_name = "Handler__long" s3_bucket = "${aws_s3_bucket.ktltst_lambda_s3.bucket}" s3_key = "${aws_s3_bucket_object.ktltst_bucket_object.key}" source_code_hash = "${base64sha256(file("../build/libs/kotless-dsl-1.0-all.jar"))}" handler = "kotless.Lambda::handleRequest" runtime = "java8" timeout = 30 role = "${aws_iam_role.ktltst_lambda_role.arn}" memory_size = 256 environment = { variables = "${var._long_envvars}" }}

resource "aws_lambda_permission" "_long" { statement_id = "AllowAPIGatewayInvoke" action = "lambda:InvokeFunction" function_name = "${aws_lambda_function._long.arn}" principal = "apigateway.amazonaws.com" source_arn = "${aws_api_gateway_deployment.ktltst_example_deployment.execution_arn}/*/*"}

resource "aws_api_gateway_resource" "_long" { parent_id = "${aws_api_gateway_rest_api.ktltst_example_rest_api.root_resource_id}" rest_api_id = "${aws_api_gateway_rest_api.ktltst_example_rest_api.id}" path_part = "long"}

resource "aws_api_gateway_method" "_long" { rest_api_id = "${aws_api_gateway_rest_api.ktltst_example_rest_api.id}" resource_id = "${aws_api_gateway_resource._long.id}" http_method = "ANY" authorization = "NONE"}

resource "aws_api_gateway_integration" "_long" { rest_api_id = "${aws_api_gateway_rest_api.ktltst_example_rest_api.id}" resource_id = "${aws_api_gateway_method._long.resource_id}" http_method = "${aws_api_gateway_method._long.http_method}" depends_on = [ "aws_api_gateway_method._long" ] integration_http_method = "POST" type = "AWS_PROXY" uri = "${aws_lambda_function._long.invoke_arn}"}

Tons of configuration!

Page 10: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

Could it be simpler?

Page 11: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

Kotlin ServerlessFrameworkLet’s change the game(at least for the Web)

Page 12: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

@Get("/hello-world")fun helloWorld(): String { return "Hello World"}

Page 13: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

Deduce configuration from code

Page 14: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov
Page 15: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

Infrastructure in Code

● Write the code with the framework of your choice

● Choose a Cloud platform to use

● Let Kotless do the deployment for you

Page 16: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

@Get("/hello-world")fun helloWorld(): String { return "Hello World"}

Code only

Page 17: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

What is in the box?Current state of the project

Page 18: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

What is in the box?

● Number of supported frameworks

● Each of them can be deployed to the cloud

● With the target runtime of your choice

Page 19: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

Supported frameworks

● Ktor

● Spring Framework

● Kotless’s own DSL

Page 20: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

Supported clouds

● Amazon Web Services

● In development

○ Google Cloud Platform

○ Microsoft Azure

Page 21: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

Supported runtimes

● Kotlin/JVM

● GraalVM

● In development

○ Kotlin/JS

Page 22: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

Runtimes CloudsFrameworks

Page 23: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

And even local starts!

Page 24: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

Local development

● Local emulation of Cloud services

● Ability to debug serverless applications

● No cloud account required to try it

Page 25: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

Summing it up

● Choose the runtime that best meets your needs

● Write an application with your favorite framework

● Test and debug it locally

● Deploy an application to your pr

Page 26: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

How does it work?A bit of internals

Page 27: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

Under the hood

● Parse an application

● Generate a cloud-agnostic Schema

● Transpile the Schema to a Terraform

● Perform the deployment

Application Terraform

Cloud

Schema

Parser Engine

Page 28: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

@DynamoDBTable("table", ReadWrite)object URLStorage { fun getByCode(code: String): String { ... }}

Cloud integration

● Permissions are granted via

Cloud-specific annotations

● Events also work via annotations

Page 29: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

DemoBetter than a thousand words

Page 30: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

What is next?Future plans

Page 31: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

In development

● Cloud Platforms○ Google Cloud Platform○ Microsoft Azure

● Runtimes○ GraalVM○ Kotlin/JS

Page 32: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

Future plans

● IntelliJ IDEA plugin○ Remote logs tailing○ Debugging

● Cloud-specific extensions○ Authentication○ Events

● And lots more!

Page 33: Kotless Kotlin Serverless - JetBrains · 2020. 10. 15. · Kotlin 1.4 Online Event October 15, 2020 @vdtankov Kotless Kotlin Serverless Framework Vladislav Tankov

Thanks!Have a nice Kotlin

@vdtankov