#serverless paradigm encourages you to use any programming language. However, some choices have benefits in terms of speed/cost. AWS supports @rustlang runtime for AWS Lambda. Writing SLS functions is super easy. Let's dive into this.. 🧵
The magic is done through lambda_runtime crate (crates.io/crates/lambda_…): your function code is passed as a closure to handler_fn (1) which returns a Handler struct
which is passed to run function that starts Lambda runtime and waits for events (2). Once they come, they are sent to your function, as the event parameter, which conveniently is a JSON Value, hence the need to use serde_json crate (3).
Finally, the result is sent back to the runtime as a variant.
A gotcha here is that if you're using AWS SDK for Rust (aws.amazon.com/it/about-aws/w…) the error type is too specific to be cast on standard Rust Error
basically, it does not comply with Rust Error and the compiler complains about missing traits in type.
In the end, in less than ten lines of code, you are able to wrap @rustlang code into an AWS Lambda function. that can run super fast and cost-effectively.