-
Notifications
You must be signed in to change notification settings - Fork 113
LambdaRuntimeClient works with Invocation #19
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
Conversation
Can one of the admins verify this patch? |
1 similar comment
Can one of the admins verify this patch? |
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.
+1 i like this change!
@swift-server-bot add to whitelist |
@swift-server-bot test this please |
8fda4d9
to
ef7f065
Compare
@@ -117,6 +118,20 @@ private extension LambdaHandler { | |||
} | |||
} | |||
|
|||
private extension LambdaContext { | |||
init(logger: Logger, eventLoop: EventLoop, invocation: Invocation) { | |||
|
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.
nit: remove empty line
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.
swiftformat .
has been run.
@@ -151,6 +149,7 @@ internal struct JsonCodecError: Error, Equatable { | |||
internal struct ErrorResponse: Codable { | |||
var errorType: String | |||
var errorMessage: String | |||
|
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.
remove empty line (use swiftformat .
)
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.
swiftformat .
has been run.
let cognitoIdentity : String? | ||
|
||
init(headers: HTTPHeaders) throws { | ||
|
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.
empty line
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.
swiftformat .
has been run.
if requestId.isEmpty { | ||
return nil | ||
|
||
guard let unixTimeMilliseconds = headers[AmazonHeaders.deadline].first else { |
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.
is it mandatory in AWS Lambda API, and if so should the lambda library enforce it? probably for different PR if the answer is yes
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.
Yes, the deadline is mandatory and we should enforce it. As said in #9 we should find a good solution how we store time here. The Context
should have some kind of remaining() function that returns the time till the deadline. Also creating a timeout handler that fires a second before the actual deadline is thinkable. As you stated this is something for a different PR though.
} | ||
|
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.
empty lines
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.
swiftformat .
has been run.
self.deadlineDate = unixTimeMilliseconds | ||
self.invokedFunctionArn = invokedFunctionArn | ||
self.traceId = traceId | ||
self.clientContext = headers["Lambda-Runtime-Client-Context"].first |
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.
not sure but maybe headers.first("Lambda-Runtime-Client-Context") is optimized?
@swift-server-bot test this please |
@swift-server-bot ok to test |
ah this is not triggering CI because its targeting the |
Open ends:
Invocation should be immutable, right? so reference could work imo
same argument as invocation?
+1 was planning to do that |
d59d850
to
a7aa066
Compare
@tomerd This is now a PR against master. Ready for final review and merge. |
a7aa066
to
99d5816
Compare
@fabianfett lets rebase |
### Motivation: - We want to store different entities that are needed when executing a handler within the LambdaContext (Logger, EventLoop, ByteBufferAllocator, …) - Currently the LambdaRuntimeClient creates the LambdaContext. Having the LambdaContext with the Logger, EventLoop and ByteBufferAllocator be created from the LambdaRuntimeClient feels to me too much for me. - Conceptionally the Lambda control plane api call is “get next Invocation” (API naming) ### Changes: - LambdaRuntimeClient responds with an Invocation and does not use the LambdaContext at all anymore. - LambdaRunner creates the LambdaContext with the Invocation, Logger and EventLoop. - LambdaContext has been renamed to Lambda.Context - Lambda.Context is a class now, since it is conceptionally not a value type and might be passed around a lot - Lambda.Context properties `traceId`, `invokedFunctionArn`, `deadline` are not optional anymore since they will be always set when executing a lambda - Creating an Invocation can fail with LambdaRuntimeClientError.invocationMissingHeader(String), if non optional headers are not present - the test MockLambdaServer and the performance test MockServer always return headers for deadline, traceId and function arn (static for now – could be changed with Behaviour flag?!) ### Open ends: - we will need to build some kind of Deadline into the context (See also #9 - probably for a different PR) - we have a stupid mapping between ByteBuffer and [UInt8] in the LambdaRunner for now (marked with two TODOs). I don’t want to change this in this PR since it will lead to huge merge conflicts down the road with the potentiall API changes we have in mind.
99d5816
to
d0ce1f3
Compare
@tomerd done |
Motivation:
LambdaContext
(Logger
,EventLoop
,ByteBufferAllocator
, …)LambdaRuntimeClient
creates the LambdaContext. Having theLambdaContext
with theLogger
,EventLoop
andByteBufferAllocator
be created from theLambdaRuntimeClient
feels too much for me.Changes:
LambdaRunner
creates theLambdaContext
with theInvocation
andLogger
(easy to addEventLoop
andByteBufferAllocator
– not for this PR).LambdaContext
has been renamed toLambda.Context
Lambda.Context
has become a class, since it is conceptually not a value type and might be passed around a lotLambda.Context
propertiestraceId
,invokedFunctionArn
,deadline
are not optional anymore since they will be always set when executing a lambdaInvocation
can fail withLambdaRuntimeClientError.invocationMissingHeader(String)
, if non optional headers are not presentMockLambdaServer
and the performance testMockServer
always return headers for deadline, traceId and function arn (static for now – could be changed with Behaviour flag – new PR?). This leads to decreased performance in performance tests, but is probably closer to real life behaviour.Open ends:
Date
#9 - probably for a different PR)ByteBuffer
and[UInt8]
in theLambdaRunner
for now (marked with two TODOs). I don’t want to change this in this PR since it will lead to huge merge conflicts down the road with the potentiall API changes we have in mind.