Crafting Lambda Functions in Rust: Book Cover (light version)

Crafting Lambda Functions in Rust

A practical guide on how to build efficient, sustainable, cost-effective serverless AWS solutions with the Rust programming language.

Yan's portrait
Serena's portrait
Anton's portrait
Monica's portrait
AJ's portrait
Natalie's portrait
Domagoj's portrait
Roberto's portrait
Eugen's portrait
Pamela's portrait
Padraig's portrait
Michael's portrait
+158

Join Yan, Serena, Anton, Monica, AJ, Natalie, and other devs who are enjoying this book!

Hey, dear serverless friend

  • Are you building web APIs with AWS Lambda and you wish there was a way to reduce cold-starts?
  • Your app is generating millions of Lambda invocations per day and the cost is starting to add up?
  • You know that Lambda is a sustainable platform, but are you wondering if you could do more?

Well, you are in the right place!

We have been building Lambda functions using the Rust programming language for a while now and we have seen impressive results in terms of efficiency, cost, and sustainability. In addition to that, Rust is a fantastic language with a great type system, which makes it easier to write elegant and correct code. Now, we are on a mission to share what we learnt so far!

With this practical e-book you will learn everything there is to know to be able to write, test and ship Lambda Functions written in Rust.

Join us in this journey and let's make the cloud a better place, one Lambda at a time!

What will you get from this book?

Are you looking to build efficient and sustainable AWS serverless solutions that won't break the bank? Wondering how the Rust programming language could help you achieve that? You've come to the right place! Check out this practical guide for all the tips and tricks you need to know to create cost-effective serverless solutions using AWS and Rust.

Hands-on code examples

Learn by doing with practical and realistic code examples that demonstrate how to write efficient and sustainable Lambda functions in Rust.

handler.rs
async fn function_handler(
    event: LambdaEvent<EventBridgeEvent<Value>>,
) -> Result<(), Error> {
    let start = Instant::now();
    let resp = reqwest::get("https://loige.co").await;
    let duration = start.elapsed();

    let timestamp = event
        .payload
        .time
        .unwrap_or_else(chrono::Utc::now)
        .format("%+")
        .to_string();
    
    let mut item = HashMap::new();
    item.insert(
        "Id".to_string(),
        AttributeValue::S(format!("{}#{}", "https://loige.co", timestamp)),
    );
    item.insert("Timestamp".to_string(), AttributeValue::S(timestamp));

    let success = match resp {
        Ok(resp) => {
            let status = resp.status().as_u16();
            item.insert("Status".to_string(), AttributeValue::N(status.to_string()));
            item.insert(
                "Duration".to_string(),
                AttributeValue::N(duration.as_millis().to_string()),
            );
            resp.status().is_success()
        }
        Err(e) => {
            item.insert("Error".to_string(), AttributeValue::S(e.to_string()));
            false
        }
    };
    item.insert("Success".to_string(), AttributeValue::Bool(success));

    let insert_result = dynamodb_client
        .put_item()
        .table_name("my_dynamo_table")
        .set_item(Some(item))
        .send()
        .await?;

    tracing::info!("Insert result: {:?}", insert_result);

    Ok(())
}

Design serverless architectures

It's not just about the Lambda functions! Learn how to design complete serverless architectures using AWS services like API Gateway, EventBridge, DynamoDB, and more using Infrastructure as Code.

A screenshot of Application Composer showcasing an API Gateway connected to multiple Lambda functions

The tools of the trade

Discover the best tools and practices to build, test, and deploy production-grade Lambda functions using Rust.

~/my-awesome-rust-lambda
$ cargo lambda build --release --arm64


What's inside?

This book consists of 15 chapters, each a step forward on your journey to bring Rust and AWS Lambda into production, unlocking gains in performance and cost efficiency. Explore the seamless integration of Rust with Lambda and witness the transformative impact it can have on your projects.

This book is a work in progress!
Progress (38.00%)

The content is subject to change.

If you get the EARLY-ACCESS bundle, you'll have access to new chapters and updates and you will be able to contribute with your precious feedback.

Buy now!

  1. Published

    Chapter 1. Rust & Lambda

    Why this combo makes a ton of sense compared to other alternatives.

  2. Published

    Chapter 2. A 'Hello, Serverless' API

    Writing our first Rust-powered Lambda Function.

  3. Published

    Chapter 3. Infrastructure as code with SAM

    How to deploy and manage Rust Lambda functions with the Serverless Application Model.

  4. Published

    Chapter 4. Integrating with external systems

    How to make arbitrary HTTP requests or to other AWS services from your Lambda functions.

  5. Published

    Chapter 5. Code organisation

    Best practices on how to organise the code for projects with multiple Lambda functions.

  6. Published

    Chapter 6. Making the code testable

    How to structure the code to be able to write good tests for your Lambda

  7. In progress

    Chapter 7. Handling different kinds of events

    How to handle AWS Specific events, custom events and arbitrary JSON in a strongly-typed way.

  8. In progress

    Chapter 8. Different ways of writing Lambda handlers

    From simple async functions, to custom structs, to implementing the Tokio Tower service trait.

  9. Planned

    Chapter 9. Configuration management and handling secrets

    Best practices to inject configuration and secrets into your Rust Lambda functions.

  10. Planned

    Chapter 10. Observing all the things

    How to make our Rust Lambda functions observable using CloudWatch or OpenTelemetry.

  11. Planned

    Chapter 11. Middlewares

    How to embrace the middleware pattern to handle cross-cutting concerns in an elegant and reusable way.

  12. Planned

    Chapter 12. Hosting existing HTTP services

    How to wrap existing HTTP services in a Lambda function to make them easily available as serverless functions.

  13. Planned

    Chapter 13. Lambda extensions

    Writing Lambda extensions using Rust.

  14. Planned

    Chapter 14. Integrating with GitHub Actions

    How to configure the integration between AWS and GitHub Actions to test, build and deploy your Lambda Functions in an automated fashion.

  15. Planned

    Appendix A. IaC alternatives

    How to use CDK or Terraform as an alternative to SAM.

Who is this book for

This book is designed for cloud developers who are passionate about Serverless and want to build green, efficient, and cost-effective serverless solutions using Rust and AWS Lambda.

This book assumes you have some basic understanding of the Rust programming language. If that's something totally new for you, we'd recommend you to check out the official Rust book (available for FREE) first.

You will also need some basic understanding of AWS and serverless. If you are new to AWS, we recommend you to try some of the FREE Lambda workshops by AWS.

A breakfast table with coffee mugs, some milk, cherries, biscuits and a red coffee mocha maker.

This book is for you if:

  • You are a cloud developer with a passion for Serverless
  • You have very basic understanding of the Rust programming language
  • You have basic knowledge of AWS and Lambda
  • You are eager to build greener, efficient, and cost-effective serverless solutions

The early-access bundle

Crafting Lambda Functions in Rust: Book Cover (light version) Crafting Lambda Functions in Rust: Book Cover (dark version)

This book is still a work in progress.
So why should you buy it now?

If you get the early-acces bundle, you won't just be supporting the authors but you will also:

  • Get the book at the discounted price of 45.90 36.02 $!
  • Get frequent updates in ePub and PDF in both light and dark mode!
  • Get access to our exclusive Discord server.
  • Have a chance to review, provide early feedback and get your name in the credits.
  • Get the unconditioned love of the authors! ♥︎
Buy now!

Meet the authors

Luciano Mammino

Senior Architect @ fourTheorem

Luciano Mammino talking at Codemotion Milan in 2023

Luciano is an AWS Serverless Hero, author and speaker. In his day to day job at fourTheorem he helps companies to get the best out of the Cloud and AWS. He is an active speaker and in the last few years he has delivered more than 130 talks in conferences and meetups around the World. He is also the author of the famous book Node.js Design Patterns.

James Eastham

Serverless Developer Advocate @ Datadog

James Eastham talking at the AWS London Summit in 2024

James Eastham is a Serverless Developer Advocate at Datadog, public speaker and content creator. Prior to Datadog, he was a Senior Cloud Architect at AWS, working with some of the biggest companies on the planet to architect and build systems on AWS. James produces content on YouTube, focused around building applications with serverless technologies. He has also produced 3 online courses on software architecture and microservices on the Dometrain platform.

What people are saying

Don't just listen to us. Listen to them.

  • Anonymous's profile picture'

    Anonymous

    I’m guilty of not having used Rust anywhere serious yet, so my knowledge is close to zero. Nevertheless, I was still able to follow because Luciano and James do a fantastic job of explaining. You’ll learn why Rust is a great fit for serverless applications, and they cover everything from setting up your environment to optimizing for performance and cost. If you’re looking to expand your skills in serverless architecture and want to see why Rust is maybe the way to go, this book is definitely worth checking out!

  • Hamed Zaghaghi's profile picture'

    Hamed Zaghaghi

    Staff Software Engineer

    Essential Guide for Rust and AWS Lambda Developers

    After a year of writing AWS Lambda functions in Rust and facing countless challenges, this book has been a game-changer. From the first few chapters, it tackles the exact issues I encountered, providing practical, clear guidance that would have saved me so much time. The book seamlessly blends Rust fundamentals with Lambda-specific insights, making it ideal for anyone looking to master both. With real-world examples and tips, it’s a must-read for anyone serious about building efficient serverless applications in Rust.

  • We are looking for more reviews! 😇.

    Do you want to help?

    Leave a review on Gumroad!

FAQs

I'm new to software engineering. Is this book suitable for me?

Absolutely! This book is crafted to be beginner-friendly, making it a great choice for those just starting in tech or transitioning from other fields. A basic understanding of Rust and AWS will be helpful, but beyond that, all you need is curiosity and a willingness to learn. The opening chapters gently introduce Lambda functions and serverless computing, designed to be easy to follow for readers from diverse backgrounds. We begin each topic (e.g. databases, testing, and specific cloud services) with a high-level overview before diving into the details of AWS Lambda and Rust.

Do I need to be an expert in Rust to enjoy this book?

No. While a basic understanding of Rust syntax is helpful, this book is beginner-friendly. If you are new to Rust, reading the official Rust book first might be beneficial. The book explains advanced Rust concepts as they are used in the context of AWS Lambda.

Do I need to be an expert in AWS to enjoy this book?

No. This book assumes only a basic familiarity with AWS. You should have an AWS account and have the AWS CLI installed and configured on your development machine. The book covers all necessary AWS serverless concepts and services, including DynamoDB, API Gateway, EventBridge, CloudWatch, SAM, and more in a way that is suitable to AWS beginners. Even if you have never used these services and tools, you should be able to follow along and understand the concepts as you progress through the book.

Is this a theory book?

No. This book balances theory and practice. You’ll build real applications, discuss technical trade-offs, and progressively enhance your examples into production-ready applications. By the end, you’ll have the knowledge needed to create production-ready serverless applications on AWS using Rust.

Are the code examples available for download?

Yes, all the code examples, including solutions to the exercises, are freely available on GitHub.

Does this book come with exercises?

Yes. Each chapter ends with challenges and exercises to reinforce the concepts learned. If you get stuck, solutions are available along with the book’s code examples.