Based on example from https://github.com/awslabs/aws-lambda-rust-runtime
- Install: rust, aws cli, zip
- (on MacOS) install libc cross-compiler
brew install filosottile/musl-cross/musl-cross && \
ln -s /usr/local/bin/x86_64-linux-musl-gcc /usr/local/bin/musl-gcc
cargo build --release --target x86_64-unknown-linux-musl
NOTE: create IAM role first (here lambda_test role is used)
zip -j lambda.zip target/x86_64-unknown-linux-musl/release/bootstrap
aws lambda create-function --function-name rustTest \
--handler doesnt.matter \
--zip-file fileb://./lambda.zip \
--runtime provided \
--role arn:aws:iam::XXXXXXXXXX:role/lambda_test \
--environment Variables={RUST_BACKTRACE=1} \
--tracing-config Mode=Active
aws lambda invoke \
--function-name rustTest \
--payload '{ "greeting": "howdy 🤙", "name": "Rust + λ"}'
output.json
jq . output.json
Output:
{
"message": "howdy 🤙, Rust + λ!"
}
Or use Makefile FTW!:
make deploy test
Rust runtime for AWS Lambda: https://github.com/awslabs/aws-lambda-rust-runtime
Setting it up: https://aws.amazon.com/blogs/opensource/rust-runtime-for-aws-lambda/