You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The run function accepts any type which implements Handler so I believe you can just have a type with state that lives across invocations of a lambda task that implements Handler
example pseudo code
structCounter{data:usize}implDefaultforCounter{fndefault() -> Self{Counter{data:0}}}implHandler<A,B>forCounter{typeError = YourErrType;typeFut = YourFutType;fncall(&mutself,req:A,ctx:Context) -> Self::Fut{// update your stateself.data += 1;// do the thing that returns Self::Fut}}fnmain(){
lambda_runtime::run(Counter::default()).await?;Ok(())}
It is possible to initialize a resource in
main
and pass it onto a closure insidehandler_fn
as a shared reference. Example: https://github.com/awslabs/aws-lambda-rust-runtime/blob/master/lambda-runtime/examples/shared_resource.rsThe downside of this method is that the initialization must be done upfront and the resource cannot be updated.
I've been trying to implement a cache that can be updated from inside the handler, but no matter what I tried it's a breaking change.
Does anyone know a way of updating a shared resource from inside the handler fn without breaking the current handler_fn interface?
The text was updated successfully, but these errors were encountered: