-
Notifications
You must be signed in to change notification settings - Fork 41
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
Custom Lambda Runtime #276
Open
scott-thomson239
wants to merge
59
commits into
typelevel:main
Choose a base branch
from
scott-thomson239:feature/custom-lambda-runtime
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
7ea939b
Bump base version
armanbilge 26b1622
Shuffle build for custom runtime
armanbilge 95efe18
http4s and cloudformation only depend on kernel
armanbilge be96317
WIP: added runtime skeleton, needs error handling
scott-thomson239 ebf5e97
fixed context creation from environment variables
scott-thomson239 6f990ad
added comments to unimplemented parts
scott-thomson239 f6a904b
used new cats effect Env instead of custom env var solution
scott-thomson239 defb679
added function to obtain LambdaRequest from response and added error …
scott-thomson239 c95cecb
renamed module and fixed handler error handling
scott-thomson239 2de1748
changed hander fiber to not raise error after cancellation
scott-thomson239 b7e6054
created custom invocation response header models
scott-thomson239 b07406c
tests work in progress
scott-thomson239 0eb162e
fixed all but one test
scott-thomson239 24c4261
added test to verify runtime can handle invocation errors correctly
scott-thomson239 602460b
fixed failing tests, although tests need refactored
scott-thomson239 25403d0
refactored tests
scott-thomson239 a65d045
added init error handling and tests
scott-thomson239 206ec6a
fixed failing test
scott-thomson239 aa06238
general clean up
scott-thomson239 39562d6
fix missing import
scott-thomson239 108c2cb
ran scalafmt
scott-thomson239 016df57
ran sbt githubWorkflowGenerate
scott-thomson239 7ce4f85
added file headers
scott-thomson239 fe73a65
added .settings(commonSettings) to lambdaRuntime and lambdaKernel
scott-thomson239 ed8cb7d
Merge branch 'main' into feature/custom-lambda-runtime
scott-thomson239 f2b7151
ran sbt githubWorkflowGenerate
scott-thomson239 0cf6033
fix type erasure warning
scott-thomson239 e3f8553
Merge branch 'main' into feature/custom-lambda-runtime
armanbilge 7c69d9e
fix for potential type inference problem in expect method and correct…
scott-thomson239 cfd8f0a
modified sbtLambda in build.sbt to include lambdaKernel.js in scripte…
scott-thomson239 accb4b6
forgot to format buld.sbt oops
scott-thomson239 6acf432
updated natchez-core in lambdaKernel and updated scalajs plugin to 1.…
scott-thomson239 2449d3e
fix for 'withFilter is not a member of IO' error
scott-thomson239 9d79651
added snapshot resolver to sbt-lambda build.sbt
scott-thomson239 3c4974c
added lambdaKernel and lambdaRuntime to build.sbt unidocs
scott-thomson239 2548296
test to see if removing rethrow from IOSetup solves compiler error
scott-thomson239 35d797f
added MatrixExclude for 2.12/native
scott-thomson239 93d55aa
changed cats-effect-kernel to cats-effect in lambdaKernel and removed…
scott-thomson239 af3b527
Make lambda headers package-private
armanbilge f3022e4
Parse/decode in single op
armanbilge d630597
More package private models
armanbilge 366248a
Build error body from `Throwable`
armanbilge ab6fa05
Define `EntityEncoder` for `LmabdaErrorBody`
armanbilge 54c3032
Reduce noise
armanbilge b5e3019
Simplifications
armanbilge d6de562
Use `Uri` for `lambdaRuntimeApi`
armanbilge 13aa8e9
Running lambda returns `Nothing`
armanbilge 3517cb7
Refactor `processEvents`
armanbilge ffa7bb3
`deadlineTimeInMs` -> `deadlineTime`
armanbilge f1f7a2c
Header names are ci strings
armanbilge f83a9de
Do not leak input in sanitized error msg
armanbilge c700129
Fix compile
armanbilge 9a49c7d
Use `embedError`
armanbilge d53f8be
refactored to have environment variables read in the initialization p…
scott-thomson239 f284899
readded Nothing instead of Unit in LambdaRuntime
scott-thomson239 3da24a9
fixed failing tests from refactoring initialization phase
scott-thomson239 8cdfc9b
remove accidental encoder import
scott-thomson239 541704e
reverted to using F[Nothing] as output type
scott-thomson239 89d1c69
changed init error test env to better reflect real behaviour
scott-thomson239 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
feral-lambda-runtime/src/main/scala/feral/lambda/runtime/LambdaErrorRequest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package feral.lambda.runtime | ||
|
||
import io.circe.Encoder | ||
|
||
final class LambdaErrorRequest(val errorMessage: String, val errorType: String, val stackTrace: List[String]) | ||
|
||
object LambdaErrorRequest { | ||
def apply(errorMessage: String, errorType: String, stackTrace: List[String]) = | ||
new LambdaErrorRequest(errorMessage, errorType, stackTrace) | ||
|
||
implicit val encoder: Encoder[LambdaErrorRequest] = | ||
Encoder.forProduct3("errorMessage", "errorType", "stackTrace")(e => | ||
(e.errorMessage, e.errorType, e.stackTrace)) | ||
} |
61 changes: 61 additions & 0 deletions
61
feral-lambda-runtime/src/main/scala/feral/lambda/runtime/LambdaRequest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package feral.lambda.runtime | ||
|
||
import cats.effect.kernel.Concurrent | ||
import io.circe._ | ||
import cats.syntax.all._ | ||
import feral.lambda.{ClientContext, ClientContextClient, ClientContextEnv, CognitoIdentity} | ||
import io.circe.syntax.EncoderOps | ||
import org.http4s.circe._ | ||
import org.http4s.{EntityDecoder, Headers, Response, headers} | ||
import org.typelevel.ci.CIString | ||
import java.util.concurrent.TimeUnit | ||
import scala.concurrent.duration.FiniteDuration | ||
|
||
final class LambdaRequest( | ||
val deadlineTimeInMs: FiniteDuration, | ||
val id: String, | ||
val invokedFunctionArn: String, | ||
val identity: Option[CognitoIdentity], | ||
val clientContext: Option[ClientContext], | ||
val body: Json | ||
) | ||
|
||
object LambdaRequest { | ||
private[this] final val requestIdHeader = "Lambda-Runtime-Aws-Request-id" | ||
private[this] final val invokedFunctionArnHeader = "Lambda-Runtime-Invoked-Function-Arn" | ||
private[this] final val deadlineTimeHeader = "Lambda-Runtime-Deadline-Ms" | ||
private[this] final val cognitoIdentityHeader = "Lambda-Runtime-Cognito-Identity" | ||
private[this] final val clientContextHeader = "Lambda-Runtime-Client-Context" | ||
def fromResponse[F[_]](response: Response[F])(implicit F: Concurrent[F]): F[LambdaRequest] = { | ||
implicit val jsonDecoder: EntityDecoder[F, Json] = jsonDecoderIncremental | ||
for { // TODO use custom header model for aws headers instead | ||
id <- F.fromOption(response.headers.get(CIString(requestIdHeader)), new NoSuchElementException(requestIdHeader)).map(_.head.value) | ||
invokedFunctionArn <- F.fromOption(response.headers.get(CIString(invokedFunctionArnHeader)), new NoSuchElementException(invokedFunctionArnHeader)).map(_.head.value) | ||
deadlineTimeInMs <- F.fromOption(response.headers.get(CIString(deadlineTimeHeader)), new NoSuchElementException(deadlineTimeHeader)).map(_.head.value.toLong) | ||
identity <- F.pure(response.headers.get(CIString(cognitoIdentityHeader)).flatMap(_.head.value.asJson.as[CognitoIdentity].toOption)) | ||
clientContext <- F.pure(response.headers.get(CIString(clientContextHeader)).flatMap(_.head.value.asJson.as[ClientContext].toOption)) | ||
body <- F.rethrow(jsonDecoder.decode(response, strict = false).value) // basically a reimplementation of response.as[Json] from dsl | ||
} yield { | ||
new LambdaRequest(FiniteDuration.apply(deadlineTimeInMs, TimeUnit.MILLISECONDS), id, invokedFunctionArn, identity, clientContext, body) | ||
} | ||
} | ||
|
||
implicit val cognitoIdentityDecoder: Decoder[CognitoIdentity] = | ||
Decoder.forProduct2("identity_id", "identity_pool_id")((identityId: String, poolId: String) => // field names are just a guess for just now until I find the schema | ||
new CognitoIdentity(identityId, poolId)) | ||
|
||
implicit val clientContextDecoder: Decoder[ClientContext] = Decoder.forProduct4("client", "custom", "env", "services")( | ||
(client: ClientContextClient, custom: JsonObject, env: ClientContextEnv, _: JsonObject) => | ||
new ClientContext(client, env, custom) | ||
) | ||
|
||
implicit val clientContextClientDecoder: Decoder[ClientContextClient] = Decoder.forProduct5("client_id", "app_title", "app_version_name", "app_version_code", "app_package_name")( | ||
(clientId: String, appTitle: String, appVersionName: String, appVersionCode: String, appPackageName: String) => | ||
new ClientContextClient(clientId, appTitle, appVersionName, appVersionCode, appPackageName) | ||
) | ||
|
||
implicit val clientContextEnvDecoder: Decoder[ClientContextEnv] = Decoder.forProduct5("platform", "model", "make", "platform_version", "locale")( | ||
(platform: String, model: String, make: String, platformVersion: String, locale: String) => | ||
new ClientContextEnv(platformVersion, platform, make, model, locale) | ||
) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response.as
is not DSL, it's a core method :)By DSL, I very specifically meant things you need to import from
org.http4s.client.dsl._