Hi, dear reader!

EDIT: It is now possible to run Rust in AWS Lambda, making this tutorial obsolete. Thank you for reading!

Today I‘ll show you a way of running Rust in AWS Lambda without incurring in the performance penalty caused by interacting with JavaScript or Python, while allowing you to test the changes locally.

The goal of this post is to develop a Lambda function that creates a thumbnail given an image, showcasing not only the use of native Rust in AWS Lambda Functions but also the ability to test the program locally.

This tutorial uses rust-aws-lambda, a crate for writing AWS Lambda functions in pure Rust. For local testing, we’ll be using the Go image from docker-lambda which allows us to run Go (and Rust) binaries, while simulating the Lambda environment.

This project [rust-aws-lambda] forgoes embedding and instead leverages lambda’s official Go support. (…) Lambda does not care that the Linux binary it runs is written in Rust rather than Go as long as they behave the same.

Setup

In order to be able to compile Rust executables, the x86_64-unknown-linux-musl target alongside musl-gcc must be installed. The target can be installed using rustup:

$ rustup target add x86_64-unknown-linux-musl

Depending on your operating system, your installation steps for musl-gcc may vary. On Ubuntu, you can use $ apt-get install musl .

That’s all that is need to compile the program. In case you want to test the binary locally, you should also have Docker installed.