Rust and Lambda are new friends. Sure, there's a great deal of momentum lately around Rust but the language has been around for almost 20 years. It struggled to take off early on but has seen its adoption increase since the creation of the Rust Foundation in 2021
AWS among many others has adopted the language for mission-critical workloads that require blazing fast performance, type-safety and solid developer experience. AWS believes so much in the language that it has built components in some of its stalwart services like S3, Cloudfront, EC2 and Lambda including the microVM technology Firecracker.
I've been working with Rust for the better part of 6 months which gives me just enough experience to highlight the things I like and have struggled with when building Lambdas. I believe that if you can get over the hurdle of learning Rust, you'll gain some amazing benefits that outweigh the challenges of "getting started". Building Lambdas with Rust.
Why Rust
I've long argued that . I appreciate the fact that I can use SAM or CDK to build and deploy my code. And I've become a fan of using CodeWhisperer with VSCode to build my Rust Lambdas.
My Experience - Building Lambdas with Rust
Before I get into my experiences, know that my desire to be a Rustacean is purely to gain more knowledge and to give me another tool that squeezes the most out of my compute cycles. I firmly believe in what I've read at above and I need to add more context as to why it's such a cool project.
First, it provides a nice way to handle local testing. If you are familiar with watching and rerunning code locally with Node or Python, Cargo Lambda will feel right at home. It can watch your codebase, recompile and make it ready to handle more test traffic.
Secondly, it gives the developer a way to test events. Yes, I know that SAM does the same thing and SAM can still be used. But Cargo Lambda works outside of SAM so if I was using CDK, I could still test with Cargo Lambda.
Third, Cargo is not only the way to get Crates into a Rust project, but it also is the preferred way to execute a build and package. Think Maven for Java. SAM and CDK both use Cargo Lambda to compile and package the Rust binary.
Deploying the Bundle
Lambda with Rust would be tough to pull off if there wasn't solid support for
. This code takes input, adds some values to the JWT claims and returns them to Cognito. I think most people would be happy with < 30ms performance as demonstrated.
Publishing EventBridge Event
project bridges that gap between SDK support and enhanced developer experience. Now this code IS flagged as experimental as it is subject to change. Didn't I just say above that I don't like experimental software in production? For something like a critical SDK into AWS, yes. But for something that is mostly data structures and working with different Lambda events, I don't have an issue. I'm comfortable with recommending builders look into this repository. I've also been fortunate to contribute to it and believe that the libraries included will make builder's lives easier. End of the day, if the experimental piece is a hold-up, a Lambda with Rust will be fine without it.
Gotchas and Not Everything is a Rose
I'd be writing too slanted of a piece if I didn't address a couple of the things that I don't particularly like about working with Rust and Lambda.
Observability
Being a big fan of Observability, observing Rust code isn't so easy. The path that I've ended up going down is using Open Telemetry. This is a Cloud Native Foundation set of standards around tracing, metrics and logging. Many Observability vendors have support for OTel but it's been a challenge to get working the way I want it to.
In addition, the tracing and subscribing pattern used in Rust is extremely powerful but can be tough to understand and learn. The documentation is good enough but it lacks quality examples.
Content Content Content
When learning something new, it's always great to have content from those that have gone before. Golang has some pretty good content written around Lambda and AWS. Some great articles and videos have been shared. Rust is still so new that it doesn't quite have that same content. It's why I am investing so heavily in putting things together with Rust in '24. I believe in Serverless and I believe in Rust and want to do what I can to share patterns and examples beyond the Hello World to get people going.
As I mentioned with Observability, other parts of using Rust with Lambda are undocumented. I've read more repositories lately than articles and while I'm determined and have some time, I know not everyone has that luxury.
Wrapping Up
I'm bullish on Serverless and also bullish on Rust. I believe that if I can build things that serve people what they want faster, cheaper and safer, why wouldn't I invest in the skills I need to be order to achieve that outcome? I know that I've said before Go is that sweet spot but I believe that to be true right now. I don't know that I'll make that argument in 6 months.
My aim this year is to help develop content that gets developers up and going with Rust and Lambda. The language is blazingly fast, it's extremely safe with its type system and borrow checker and the syntax (once learned) is easy enough to work with. Throw in tools like Cargo Lambda and the Rust Lambda Runtime project and as a builder, I have what I need to be highly productive.
The future is Rusty!
Thanks for reading and Happy Building!
SOCIAL SHARE CARD GENERATOR