-
Notifications
You must be signed in to change notification settings - Fork 65
SWIFT-1536 Add AWS Lambda Example #771
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
SWIFT-1536 Add AWS Lambda Example #771
Conversation
Examples/AWSLambda.swift
Outdated
let ok: Int | ||
} | ||
|
||
Lambda.run { (_, _: Input, callback: @escaping (Result<Response, Error>) -> Void) in |
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.
Unfortunately this function does not support async/await yet. I haven't worked much (if at all) with the EventLoopFuture
API, so let me know if there's a more idiomatic way to structure the result handling below.
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.
it looks like we could write a little type that implements the LambdaHandler
protocol (which has a handle
method that is async
), something like this:
https://github.com/swift-server/swift-aws-lambda-runtime/blob/568897c8b7d94d921aa53cb367718d37c2cc20e6/Tests/AWSLambdaRuntimeCoreTests/LambdaHandlerTest.swift#L83-L103
and then you can just pass an instance of the handler to Lambda.run
. I think that would let us sidestep having to deal with the callback here
Examples/AWSLambda.swift
Outdated
let ok: Int | ||
} | ||
|
||
Lambda.run { (_, _: Input, callback: @escaping (Result<Response, Error>) -> Void) in |
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.
it looks like we could write a little type that implements the LambdaHandler
protocol (which has a handle
method that is async
), something like this:
https://github.com/swift-server/swift-aws-lambda-runtime/blob/568897c8b7d94d921aa53cb367718d37c2cc20e6/Tests/AWSLambdaRuntimeCoreTests/LambdaHandlerTest.swift#L83-L103
and then you can just pass an instance of the handler to Lambda.run
. I think that would let us sidestep having to deal with the callback here
Examples/AWSLambda.swift
Outdated
@@ -0,0 +1,41 @@ | |||
// begin lambda connection example 1 |
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.
I think it would be good to put this in a little swift package like our other examples, so we can show what dependencies/versions people need to depend on, and also so we can test that the code continues to compile.
there's a step in our release script that builds our existing examples via calling build-examples.sh; we should edit that script to include this example too
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.
lgtm! nice job with this
Adds an example for using the driver with AWS Lambda. Note that only the first connection example is included because the driver does not currently support AWS authentication (I've added a note of this in SWIFT-783).
I've verified that the example works by running it manually in Lambda.