softprops / serverless-rust

⚡ 🦀 a serverless framework plugin for rustlang applications
https://www.npmjs.com/package/serverless-rust
MIT License
541 stars 81 forks source link

Example with async handler? #73

Closed amaury1093 closed 4 years ago

amaury1093 commented 4 years ago

💡 Feature description

I would like to see examples using async handlers (is it supported already?). The echo, http and multi examples only show sync handlers.

💻 Basic example

Does something like this already work?

fn main() {
    lambda!(handler)
}

async fn handler(
    event: Value,
    _: Context,
) -> Result<Value, HandlerError> {
    f().await?
}
kahlil29 commented 4 years ago

Yes @amaurymartiny this works fine. It kind of has to work because a lot of AWS-related operations in rusoto-* are async functions. Did you try this out and it didn't work for you? What's the error?

softprops commented 4 years ago

@kahlil29 you'll likely want to check out the lasted rust runtime. It's not released yet but you can dependent on it as a git dependency. It's async by default

softprops commented 4 years ago

I'll be rolling out new examples soon

softprops commented 4 years ago

If it helps I posted a trivial example here https://github.com/softprops/dynomite/blob/master/dynomite/examples/lambda.rs

kahlil29 commented 4 years ago

@amaurymartiny I hope this helps you. I think I was tagged by mistake 😅

softprops commented 4 years ago

@amaurymartiny all examples and templates have been updated to use the latest async version of the rust lambda runtime which is at this time an unreleased git dependency. When it's released I'll update to reflect the crates.io release