This is a working example of running a Rust Lambda on AWS based on the README.md of aws-lambda-rust.
There are several steps that aren't described or have changed and some easy quality of life improvements so I'm documenting my example.
You can run your lambda locally out of your target
folder with the
right configuration.
In Cargo.toml
you will need to override the name of the final binary:
[[bin]]
name = "bootstrap"
path = "src/main.rs"
From the project root you can run the lambda:
docker run --rm -v `pwd`/target/x86_64-unknown-linux-musl/release/:/var/task:ro,delegated lambci/lambda:provided handler '{"firstName": "world"}'
Note:
handler '{"json": "event"}'
is required here, the container seems to accept input on stdin
You will definitely need this to use docker
for testing and I haven't
gotten my system default target to work in AWS so likely this is a
requirement.
rustup target add x86_64-unknown-linux-musl
- Make sure you have
musl-gcc
. On Ubuntusudo apt install musl-tools
If you don't want musl
to be the default target then you'll need to call
cargo build --release --target x86_64-unknown-linux-gnu
. If you're
comfortable with making it the default you can add a .cargo/config
file
to make it the default build target.