From 26cb0a07b2edcaa1c2176e0cfbee3987dc29906c Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Fri, 19 May 2023 14:51:14 +0200 Subject: [PATCH] [aws-serverless-example] Add example for usage of Native LambdaApi --- build.sbt | 4 ++++ .../aws/examples/LambdaApiExample.scala | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 serverless/aws/examples/src/main/scalanative/sttp/tapir/serverless/aws/examples/LambdaApiExample.scala diff --git a/build.sbt b/build.sbt index 68d5f1e3a5..2a40e9006d 100644 --- a/build.sbt +++ b/build.sbt @@ -1646,6 +1646,10 @@ lazy val awsExamples: ProjectMatrix = (projectMatrix in file("serverless/aws/exa scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) } ) ) + .nativePlatform( + scalaVersions = scala2Versions, + settings = commonNativeSettings + ) .dependsOn(awsLambda) lazy val awsExamples2_12 = awsExamples.jvm(scala2_12).dependsOn(awsSam.jvm(scala2_12), awsTerraform.jvm(scala2_12), awsCdk.jvm(scala2_12)) diff --git a/serverless/aws/examples/src/main/scalanative/sttp/tapir/serverless/aws/examples/LambdaApiExample.scala b/serverless/aws/examples/src/main/scalanative/sttp/tapir/serverless/aws/examples/LambdaApiExample.scala new file mode 100644 index 0000000000..8f51ee7570 --- /dev/null +++ b/serverless/aws/examples/src/main/scalanative/sttp/tapir/serverless/aws/examples/LambdaApiExample.scala @@ -0,0 +1,16 @@ +package sttp.tapir.serverless.aws.examples + +import cats.effect.IO +import cats.syntax.all._ +import sttp.tapir._ +import sttp.tapir.server.ServerEndpoint +import sttp.tapir.serverless.aws.lambda.runtime._ + +object LambdaRuntime extends AwsLambdaIORuntime { + val helloEndpoint: ServerEndpoint[Any, IO] = endpoint.get + .in("api" / "hello") + .out(stringBody) + .serverLogic { _ => IO.pure(s"Hello!".asRight[Unit]) } + + override val endpoints = Seq(helloEndpoint) +}