This is an example of using serverless-rust. It contains a simple hello
lambda function
- Clone the repo:
git clone git@github.com:SerheyDolgushev/serverless-rust-example.git cd serverless-rust-example
- Install Node.js dependencies:
npm install --only=dev
serverless-rust allows invoking rust lambda functions locally. Please run following command to run hello
function with {"firstName": "Sherlock", "lastName": "Holmes"}
payload:
npx serverless invoke local -f hello \
-d '{"action": "greet", "firstName": "Sherlock"}' \
--env RUST_LOG=warn,lambda=debug
The output will contain function logs and response:
...
[2022-04-12T14:38:59Z DEBUG lambda] Event data: {"action":"greet","firstName":"Sherlock"}
...
{"greeting":"Hello, Sherlock!"}
Please be aware that local invoke will be stuck if the rust function is panicking (AWS Local Invocation is stuck when rust is panicking). The simplest way to reproduce it is to call:
npx serverless invoke local -f hello -d '{action": "panic"}'
It can be fixed by manually killing the docker container by running the following command in a new terminal:
docker stop $(docker ps --filter "ancestor=sls-docker-provided" -q)
Once the docker container is killed the previously stuck function will be done, and its output will be printed:
...
thread 'main' panicked at 'Panic: message!', src/main.rs:19:20
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
...