Skip to content

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

Merged

Conversation

isabelatkinson
Copy link
Contributor

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.

let ok: Int
}

Lambda.run { (_, _: Input, callback: @escaping (Result<Response, Error>) -> Void) in
Copy link
Contributor Author

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.

Copy link
Contributor

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

@isabelatkinson isabelatkinson marked this pull request as ready for review August 11, 2022 20:49
let ok: Int
}

Lambda.run { (_, _: Input, callback: @escaping (Result<Response, Error>) -> Void) in
Copy link
Contributor

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

@@ -0,0 +1,41 @@
// begin lambda connection example 1
Copy link
Contributor

@kmahar kmahar Aug 11, 2022

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

Copy link
Contributor

@kmahar kmahar left a 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

@isabelatkinson isabelatkinson merged commit 4718960 into mongodb:main Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants