Luca Bianchi Profile picture
Jan 19 6 tweets 3 min read
#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.

This can be easily solved by boxing the error (4) which handles dynamic error types (doc.rust-lang.org/rust-by-exampl…)
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.

Go build #serverless!
#100DaysOfCode

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Luca Bianchi

Luca Bianchi Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(