Skip to content

Lambda Handler #1

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

Closed
skorfmann opened this issue Jan 20, 2023 · 3 comments
Closed

Lambda Handler #1

skorfmann opened this issue Jan 20, 2023 · 3 comments

Comments

@skorfmann
Copy link
Contributor

Trying to build a Rust Lambda Handler (based on https://github.com/awslabs/aws-lambda-rust-runtime). However, when integrating this I get the following error:

error: future cannot be sent between threads safely
   --> cloud/lib/rust-runtime/src/main.rs:37:9
    |
37  |     run(service_fn(function_handler)).await
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `function_handler` is not `Send`
    |
    = help: within `impl std::future::Future<Output = Result<lambda_http::Response<lambda_http::Body>, Box<(dyn StdError + std::marker::Send + std::marker::Sync + 'static)>>>`, the trait `std::marker::Send` is not implemented for `Rc<FsModuleLoader>`
note: future is not `Send` as this value is used across an await
   --> /Users/sebastian/projects/byt/runtime/runtime/myworker/mod.rs:182:61
    |
110 |     let module_loader = Rc::new(FsModuleLoader);
    |         ------------- has type `Rc<FsModuleLoader>` which is not `Send`
...
182 |     let module_id = worker.preload_main_module(&main_module).await.unwrap();
    |                                                             ^^^^^^ await occurs here, with `module_loader` maybe used later
...
186 | }
    | - `module_loader` is later dropped here
note: required by a bound in `lambda_http::run`
   --> /Users/sebastian/.cargo/registry/src/github.com-1ecc6299db9ec823/lambda_http-0.7.3/src/lib.rs:185:16
    |
185 |     S::Future: Send + 'a,
    |                ^^^^ required by this bound in `lambda_http::run`

Have tried to move around a few things without much success, just slightly different error descriptions of the same category.

The relevant code for the lambda handler is here and the runtime

Any idea @certainty ?

@skorfmann
Copy link
Contributor Author

Feedback in the Deno Discord channel was, that "Javascript is single-threaded, so JsRuntime / {Main,Module}Worker aren't Send or Sync" and that the Deno Rust bindings aren't supporting this at the moment.

I'll try to build a custom Lambda invocation and swap out the AWS Lambda Runtime.

@skorfmann
Copy link
Contributor Author

Well, got it to build after digging trough the code / issues in https://github.com/awslabs/aws-lambda-rust-runtime

One interesting thing I learned in this issue is, that the AWS Lambda Rust Runtime is using the multi threaded Tokio executor, where Deno is using the single threaded one. Even tried to use the single threaded version in this context, but that didn't work either. So, had to dig further.

Then came across awslabs/aws-lambda-rust-runtime#310 which talks about static lifetime requirements. Don't even really know what that's about, however the problems described there seemed to be familiar. Essentially, I swapped the lambda-http crate for the lambda-runtime crate based on this example and at least it builds correctly that way.

My hunch that that it's somehow the difference between these two run implementations, but that's a wild, uneducated guess :) lambda-http#run vs lambda-runtime#run

@skorfmann
Copy link
Contributor Author

And it actually works 🎉

Screenshot 2023-01-22 at 17 53 46

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

No branches or pull requests

1 participant