Skip to content

Custom context #458

Closed
Closed

Description

@0xDjole

I am trying to create custom context that gets reused between invocations.
Here specifically trying to reuse mongodb client.

 // ...initing mongo database

  let custom_context = CustomContext {
        mongo_database: Some(mongo_database),
   };

   lambda_runtime::run(handler_fn(|event: Request, ctx: Context| {
       execute(event, ctx, &custom_context)
   }))

Getting: Closure may outlive the current function, but it borrows custom_context, which is owned by the current function

Can handler_fn be used to support something like this?

Activity

  1. calavera commented on Apr 3, 2022

    @calavera
    Contributor

    Yes, See this example that shares custom resources: https://github.com/awslabs/aws-lambda-rust-runtime/blob/main/lambda-http/examples/shared-resources-example.rs

    Your current code is bumping into Rust borrowing challenges. There is a good explanation on how it works here: https://blog.logrocket.com/introducing-the-rust-borrow-checker/

  2. locked and limited conversation to collaborators on Apr 3, 2022
  3. converted this issue into a discussion #459 on Apr 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions