Skip to content

Commit

Permalink
Add server options to AWS Lambda handler (#4223)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiuszkierat authored Dec 27, 2024
1 parent 3ba4fa8 commit 874fb13
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import java.io.{InputStream, OutputStream}

/** Used by [[AwsCdkAppTemplate]] for integration tests
*/
object CdkTestLambdaHandler extends LambdaHandler[IO, AwsRequestV1] {
object CdkTestLambdaHandler extends LambdaHandler[IO, AwsRequestV1](AwsCatsEffectServerOptions.noEncoding[IO]) {
override protected def getAllEndpoints: List[ServerEndpoint[Any, IO]] = allEndpoints.toList

override def handleRequest(input: InputStream, output: OutputStream, context: Context): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import cats.effect.unsafe.implicits.global
import com.amazonaws.services.lambda.runtime.Context
import io.circe.generic.auto._
import sttp.tapir.server.ServerEndpoint
import sttp.tapir.serverless.aws.lambda.{AwsRequestV1, LambdaHandler}
import sttp.tapir.serverless.aws.lambda.{AwsCatsEffectServerOptions, AwsRequestV1, LambdaHandler}

import java.io.{InputStream, OutputStream}

class IOLambdaHandlerV1 extends LambdaHandler[IO, AwsRequestV1] {
class IOLambdaHandlerV1 extends LambdaHandler[IO, AwsRequestV1](AwsCatsEffectServerOptions.noEncoding[IO]) {

override protected def getAllEndpoints: List[ServerEndpoint[Any, IO]] = TestEndpoints.all[IO].toList

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import sttp.tapir.serverless.aws.lambda._

import java.io.{InputStream, OutputStream}

object LambdaApiExample extends LambdaHandler[IO, AwsRequest] {
object LambdaApiExample extends LambdaHandler[IO, AwsRequest](AwsCatsEffectServerOptions.noEncoding[IO]) {

val helloEndpoint: ServerEndpoint[Any, IO] = endpoint.get
.in("api" / "hello")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import sttp.tapir.serverless.aws.lambda._

import java.io.{InputStream, OutputStream}

object LambdaApiV1Example extends LambdaHandler[IO, AwsRequestV1] {
object LambdaApiV1Example extends LambdaHandler[IO, AwsRequestV1](AwsCatsEffectServerOptions.noEncoding[IO]) {

val helloEndpoint: ServerEndpoint[Any, IO] = endpoint.get
.in("api" / "hello")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import cats.effect.unsafe.implicits.global
import com.amazonaws.services.lambda.runtime.Context
import io.circe.generic.auto._
import sttp.tapir.server.ServerEndpoint
import sttp.tapir.serverless.aws.lambda.{AwsRequest, LambdaHandler}
import sttp.tapir.serverless.aws.lambda.{AwsCatsEffectServerOptions, AwsRequest, AwsServerOptions, LambdaHandler}
import java.io.{InputStream, OutputStream}

class IOLambdaHandlerV2 extends LambdaHandler[IO, AwsRequest] {
class IOLambdaHandlerV2 extends LambdaHandler[IO, AwsRequest](AwsCatsEffectServerOptions.noEncoding[IO]) {

override protected def getAllEndpoints: List[ServerEndpoint[Any, IO]] = allEndpoints.toList

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ import java.nio.charset.StandardCharsets
* @tparam R
* AWS API Gateway request type [[AwsRequestV1]] or [[AwsRequest]]. At the moment mapping is required as there is no support for
* generating API Gateway V2 definitions with AWS CDK v2.
* @param options
* Server options of type AwsServerOptions.
*/
abstract class LambdaHandler[F[_]: Sync, R: Decoder] extends RequestStreamHandler {
abstract class LambdaHandler[F[_]: Sync, R: Decoder](options: AwsServerOptions[F]) extends RequestStreamHandler {

protected def getAllEndpoints: List[ServerEndpoint[Any, F]]

protected def process(input: InputStream, output: OutputStream): F[Unit] = {
val server: AwsCatsEffectServerInterpreter[F] =
AwsCatsEffectServerInterpreter(AwsCatsEffectServerOptions.noEncoding[F])
val server: AwsCatsEffectServerInterpreter[F] = AwsCatsEffectServerInterpreter(options)

for {
allBytes <- Sync[F].blocking(input.readAllBytes())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import java.nio.charset.StandardCharsets
*
* @tparam Env
* The Environment type of the handler .
* @tparam options
* @param options
* Server options of type AwsServerOptions.
*/
abstract class ZioLambdaHandler[Env: RIOMonadError](options: AwsServerOptions[RIO[Env, *]]) {
Expand Down

0 comments on commit 874fb13

Please sign in to comment.