This repo contains experimental Rust code written as research for a blog series about attempting to replace my usages of FastAPI with a Rust alternative.
- Install AWS SAM CLI:
pipx install aws-sam-cli==1.12.0 - Switch to the nightly toolchain:
rustup toolchain install nightly - Set nightly as the default toolchain:
rustup default nightly - Add MUSL target:
rustup target add x86_64-unknown-linux-musl - Install MUSL cross-compile tool:
brew install FiloSottile/musl-cross/musl-cross - Soft link musl-gcc:
ln -s /usr/local/bin/x86_64-linux-musl-gcc /usr/local/bin/musl-gcc
- Comment out any versions of the code you don't actually want to build in
template.yaml - Run
sam buildand wait... it's going to take a long time for the first build. - Run
sam local start-apito start a local webserver which will serve the "lambdas". You must have Docker installed and running for this to work.
At the top level of this project is metadata which binds all the experiments together. Each experiment is its own crate, registered in the top level Cargo.toml workspace. If you want more information about a particular experiment, check out the README for that crate.
template.yaml is configuration data for AWS SAM which registers a lambda function for each experiment for use with API Gateway. Note that none of this code has necessarily been tested with a real Lambda/API Gateway, development is done using sam local to save some headache.
A Makefile is required in order to tell SAM how to build the crates. There is one entry per Lambda function called build-.
For more general information on deploying Rust code to AWS Lambda, check out this blog post and the Netlify's fork of the AWS Rust Runtime.