TutorialbeginnerPart 2 of 18

Installation

Setting up the Rust toolchain and AWS SAM for serverless development.

April 12, 20263 min read

What you'll learn

  • Rust installation
  • AWS cli installation
  • SAM installation
Prerequisites:Basic cli command

You can clone the completed project from GitHub↗ to follow along or use it as a reference.

Getting your environment ready is usually the most annoying part of learning something new. For Rust on Lambda, you need a few specific tools to handle the building and deployment process.

Here is exactly what you need to install based on your OS.

1. Rust

Install the standard toolchain using the official script.

Terminal
bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

2. AWS CLI

You can use your package manager, but the official installer is more reliable.

Terminal
bash
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

3. AWS SAM CLI

Download the zip and run the install script.

Terminal
bash
wget https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-x86_64.zip
unzip aws-sam-cli-linux-x86_64.zip -d sam-installation
sudo ./sam-installation/install

4. Cargo Lambda

This is what we'll use to build the code for the Lambda environment.

Terminal
bash
pip3 install cargo-lambda

Handling cross-compilation

AWS Lambda runs on Linux. If you're developing on a Mac or Windows, you need to tell Rust how to build code for that specific Linux environment.

cargo-lambda handles most of this, but you still need to add the target to your toolchain:

Terminal
bash
rustup target add x86_64-unknown-linux-musl

Why Musl?

I use the musl target because it creates a statically linked binary. This means the binary "carries" everything it needs and doesn't depend on libraries being already present in the Lambda environment. It avoids a lot of "file not found" errors.

Check if everything works

Run these in your terminal to make sure everything is ready:

  • rustc --version
  • aws --version
  • sam --version
  • cargo lambda --version

At the point of writing this, my development version is:

  • rustc: 1.94.1
  • aws: 2.17.32 Python/3.11.9 Linux/6.17.0-19-generic exe/x86_64.ubuntu.24
  • aws-sam-cli: 1.142.1
  • cargo-lambda: 1.8.6

Now that everything is set up, we can actually start building something. In the next post, we'll use AWS SAM to create our first project.