Kotlin Serverless Framework Vladislav Tankov What is serverless? - - PowerPoint PPT Presentation

kotlin serverless framework
SMART_READER_LITE
LIVE PREVIEW

Kotlin Serverless Framework Vladislav Tankov What is serverless? - - PowerPoint PPT Presentation

Kotlin Serverless Framework Vladislav Tankov What is serverless? cloud-computing execution model , in which the cloud provider runs the server and dynamically manages the allocation of machine resources Wikipedia How are serverless


slide-1
SLIDE 1

Vladislav Tankov

Kotlin Serverless Framework

slide-2
SLIDE 2

What is serverless?

slide-3
SLIDE 3

cloud-computing execution model, in which the cloud provider runs the server and dynamically manages the allocation of machine resources

Wikipedia

slide-4
SLIDE 4

How are serverless applications built?

  • Three simple steps:

○ Take small elements – stateless functions ○ Compose them with events into an application ○ Deploy it to Cloud runtime

slide-5
SLIDE 5
slide-6
SLIDE 6

Still, the idea is pretty simple

slide-7
SLIDE 7

Implementation should also be simple, right?

slide-8
SLIDE 8

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

slide-9
SLIDE 9

People deploy Serverless applications with Infrastructure as Code approach

slide-10
SLIDE 10

Infrastructure as Code (IaC) is the process of managing and provisioning computer data centers through machine-readable definition files, rather than physical hardware configuration or interactive configuration tools

Wikipedia

slide-11
SLIDE 11

With Infrastructure as Code it is not that simple

slide-12
SLIDE 12

Tons of configuration

  • 100+ lines for this function
  • 1000+ lines for a simple site
  • Separate language for configuration

### API route: GET /long variable "_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}" }

slide-13
SLIDE 13

Could it be simpler?

slide-14
SLIDE 14

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

slide-15
SLIDE 15

Infrastructure can be deduced from code

slide-16
SLIDE 16

Infrastructure SHOULD be deduced from code

slide-17
SLIDE 17

Infrastructure in Code

  • Application framework and deployment tool:

○ Write the code with the help of the framework ○ Introspect the code during deployment ○ Create infrastructure and deploy the application ○ Weave the application into the infrastructure in runtime

slide-18
SLIDE 18

That is what Kotless does

slide-19
SLIDE 19

Actual Kotless code

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

slide-20
SLIDE 20

Kotless

  • Infrastructure in Code tool for Kotlin:

○ Kotless DSL for HTTP events ○ Gradle plugin for deployment ○ Uses Terraform under the hood ○ Supports AWS

slide-21
SLIDE 21

Kotless-based application

slide-22
SLIDE 22

How does it work?

slide-23
SLIDE 23

What it gives us

  • Cloud agnostic scheme
  • Abstraction of deployment
  • Abstraction of DSL
slide-24
SLIDE 24

Why not support existing framework?

slide-25
SLIDE 25

Ktor-based application

slide-26
SLIDE 26

Several DSLs

slide-27
SLIDE 27

Seamless serverless

  • Write the code with any web framework you like

○ Ktor

  • Run it locally
  • Deploy it

○ As a serverless app to cloud ○ As a standalone app in-house

slide-28
SLIDE 28

Let’s go even further

slide-29
SLIDE 29

Scheduling?

@Scheduled(every5Minutes) fun scheduledRoute() { println("What a lovely day!") }

slide-30
SLIDE 30

Permissions?

@DynamoDBTable("table", ReadWrite)

  • bject URLStorage {

fun getByCode(code: String): String? { ... } }

slide-31
SLIDE 31

Code may fully define

  • API interaction: @Get, @Post, ...
  • Events handling: @Scheduled, …
  • Permissions requirements: @DynamoDBTable, ...
  • Shared structures: Queue, List, ...
  • Calls of functions: async { … }, ….
slide-32
SLIDE 32

Kotless advanced features

slide-33
SLIDE 33

What’s next?

slide-34
SLIDE 34

More is coming

  • We are working hard on:

○ Supporting other clouds ○ Kotless MPP ○ Extended event handling ○ Much more

slide-35
SLIDE 35

Give Kotless a try!

github.com/JetBrains/Kotless

vladislav.tankov@jetbrains.com

Remember to vote!

slide-36
SLIDE 36

Serverless IS

  • Very popular topic:

○ Top-growth cloud service 2nd year ○ Almost as popular as Kotlin on StackOverflow ○ 10 percent less interesting than ML (39% / 49%) ○ Even standardization is on the way ■ CloudEvents.io ■ Knative

slide-37
SLIDE 37

Serverless IS

  • Applications building approach:

○ Decouple the app as much as possible ○ Make use of cloud provider’s managed services ○ Connect it with the outer world via provider’s API

slide-38
SLIDE 38

Why to serverless?

8

slide-39
SLIDE 39

Make the provider manage your infrastructure

slide-40
SLIDE 40

Why to serverless

  • Benefits all the way:

○ Automatic scaling ○ Fault tolerance ○ Cost ■ Is it?

slide-41
SLIDE 41

Why to serverless

  • Hundreds of frameworks:

○ Infrastructure as a Code ■ Serverless.com ■ CDK ■ Terraform ○ Infrastructure in a Code ■ AWS Chalice ■ Kotless ■ Osiris

slide-42
SLIDE 42

Why to serverless

  • Availability:

○ Courses ○ Books ○ Samples ○ Researches

slide-43
SLIDE 43

The Great Serverless Myth

13

slide-44
SLIDE 44

Serverless is not a thing without servers

slide-45
SLIDE 45

It’s all about management

  • Reducing the pain of managing:

○ Scale ○ Price ○ SLA ○ Complexity

slide-46
SLIDE 46

Serverless is overcomplicated

15