Skip to content

SerheyDolgushev/serverless-rust-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serverless Rust Example

This is an example of using serverless-rust. It contains a simple hello lambda function

Installation

  1. Clone the repo:
    git clone git@github.com:SerheyDolgushev/serverless-rust-example.git
    cd serverless-rust-example
  2. Install Node.js dependencies:
    npm install --only=dev

Usage

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!"}

Known issues

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
...

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages