Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add server options to AWS Lambda handler #4223

Merged
merged 9 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading