Installation
Setting up the Rust toolchain and AWS SAM for serverless development.
What you'll learn
- Rust installation
- AWS cli installation
- SAM installation
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.
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:
rustup target add x86_64-unknown-linux-muslWhy 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.1aws: 2.17.32 Python/3.11.9 Linux/6.17.0-19-generic exe/x86_64.ubuntu.24aws-sam-cli: 1.142.1cargo-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.