-
-
Notifications
You must be signed in to change notification settings - Fork 49
feat: lambda custom runtime #496
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
Open
i10416
wants to merge
15
commits into
typelevel:main
Choose a base branch
from
i10416:feat/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 all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
49e0bde
feat: lambda custom runtime
i10416 25de4fd
chore: use shorthand syntax
i10416 b0c21c2
fix: previous artifacts for new modules do not exist
i10416 0d6f1c3
tidy: make mima filter stricter
i10416 88be274
fix: LambdaRuntime should not run handler in parallel
i10416 9a94ba3
setup: context propagates trace id from request
i10416 646ace4
resolve conflict
i10416 fed8172
chore: remove unnecessary type annotations
i10416 ce0110c
fix: suppress bin compat errors
i10416 7137dd3
fix: compile errors
i10416 feef4c9
tidy: better POST request error handling
i10416 7d3b9c1
chore: add runtime-function-error-type header
i10416 d1976d1
chore: correct the wrong doc
i10416 352ff80
feat: runtime binding now propagates trace id from env
i10416 6857ff2
chore: use shorthand syntax
i10416 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 hidden or 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 hidden or 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 hidden or 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ sealed abstract class Context[F[_]] { | |
| def identity: Option[CognitoIdentity] | ||
| def clientContext: Option[ClientContext] | ||
| def remainingTime: F[FiniteDuration] | ||
| def xRayTraceId: Option[String] | ||
|
|
||
| final def mapK[G[_]](f: F ~> G): Context[G] = | ||
| new Context.Impl( | ||
|
|
@@ -45,12 +46,13 @@ sealed abstract class Context[F[_]] { | |
| logStreamName, | ||
| identity, | ||
| clientContext, | ||
| f(remainingTime) | ||
| f(remainingTime), | ||
| xRayTraceId | ||
| ) | ||
|
|
||
| } | ||
|
|
||
| object Context extends ContextCompanionPlatform { | ||
| object Context { | ||
| def apply[F[_]]( | ||
| functionName: String, | ||
| functionVersion: String, | ||
|
|
@@ -74,7 +76,37 @@ object Context extends ContextCompanionPlatform { | |
| logStreamName, | ||
| identity, | ||
| clientContext, | ||
| remainingTime) | ||
| remainingTime, | ||
| None | ||
| ) | ||
| } | ||
| def apply[F[_]]( | ||
| functionName: String, | ||
| functionVersion: String, | ||
| invokedFunctionArn: String, | ||
| memoryLimitInMB: Int, | ||
| awsRequestId: String, | ||
| logGroupName: String, | ||
| logStreamName: String, | ||
| identity: Option[CognitoIdentity], | ||
| clientContext: Option[ClientContext], | ||
| remainingTime: F[FiniteDuration], | ||
| xRayTraceId: Option[String] | ||
| )(implicit F: Applicative[F]): Context[F] = { | ||
| val _ = F // might be useful for future compatibility | ||
| new Impl( | ||
| functionName, | ||
| functionVersion, | ||
| invokedFunctionArn, | ||
| memoryLimitInMB, | ||
| awsRequestId, | ||
| logGroupName, | ||
| logStreamName, | ||
| identity, | ||
| clientContext, | ||
| remainingTime, | ||
| xRayTraceId | ||
| ) | ||
| } | ||
|
|
||
| private final case class Impl[F[_]]( | ||
|
|
@@ -87,7 +119,8 @@ object Context extends ContextCompanionPlatform { | |
| logStreamName: String, | ||
| identity: Option[CognitoIdentity], | ||
| clientContext: Option[ClientContext], | ||
| remainingTime: F[FiniteDuration] | ||
| remainingTime: F[FiniteDuration], | ||
| xRayTraceId: Option[String] | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. propagate |
||
| ) extends Context[F] { | ||
| override def productPrefix = "Context" | ||
| } | ||
|
|
||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
71 changes: 71 additions & 0 deletions
71
lambda-runtime-binding/js/src/main/scala/feral/lambda/ContextPlatform.scala
This file contains hidden or 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,71 @@ | ||
| /* | ||
| * Copyright 2021 Typelevel | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package feral.lambda | ||
| import cats.effect.Sync | ||
| import cats.effect.std.Env | ||
| import cats.syntax.functor._ | ||
| import io.circe.JsonObject | ||
| import io.circe.scalajs._ | ||
|
|
||
| import scala.concurrent.duration._ | ||
|
|
||
| private[lambda] object ContextPlatform { | ||
|
|
||
| private[lambda] def fromJS[F[_]: Sync: Env](context: facade.Context): F[Context[F]] = Env[F] | ||
| .get("_X_AMZN_TRACE_ID") | ||
| .map(traceId => | ||
| Context( | ||
| context.functionName, | ||
| context.functionVersion, | ||
| context.invokedFunctionArn, | ||
| context.memoryLimitInMB.toInt, | ||
| context.awsRequestId, | ||
| context.logGroupName, | ||
| context.logStreamName, | ||
| context.identity.toOption.map { identity => | ||
| CognitoIdentity(identity.cognitoIdentityId, identity.cognitoIdentityPoolId) | ||
| }, | ||
| context | ||
| .clientContext | ||
| .toOption | ||
| .map { clientContext => | ||
| ClientContext( | ||
| ClientContextClient( | ||
| clientContext.client.installationId, | ||
| clientContext.client.appTitle, | ||
| clientContext.client.appVersionName, | ||
| clientContext.client.appVersionCode, | ||
| clientContext.client.appPackageName | ||
| ), | ||
| ClientContextEnv( | ||
| clientContext.env.platformVersion, | ||
| clientContext.env.platform, | ||
| clientContext.env.make, | ||
| clientContext.env.model, | ||
| clientContext.env.locale | ||
| ), | ||
| clientContext | ||
| .custom | ||
| .toOption | ||
| .flatMap(decodeJs[JsonObject](_).toOption) | ||
| .getOrElse(JsonObject.empty) | ||
| ) | ||
| }, | ||
| Sync[F].delay(context.getRemainingTimeInMillis().millis), | ||
| traceId | ||
| )) | ||
| } |
This file contains hidden or 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
File renamed without changes.
File renamed without changes.
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.
Uh oh!
There was an error while loading. Please reload this page.