Skip to content

mbergkvist/serverless-rust-demo

 
 

Repository files navigation

Serverless Rust Demo

build

Architecture diagram

This is a simple serverless application built in Rust. It consists of an API Gateway backed by four Lambda functions and a DynamoDB table for storage.

This single crate will create five different binaries, one for each Lambda function. It uses an hexagonal architecture pattern to decouple the entry points, from the main domain logic, the storage component, and the event bus component.

Code walkthrough

If you want to learn more about Rust on Lambda and how this project is structured, you can find a recorded walkthrough on the AWS Twitch channel.

🏗️ Deployment and testing

Requirements

Commands

You can use the following commands at the root of this repository to test, build, and deploy this project:

# Run unit tests
make tests-unit

# Compile and prepare Lambda functions
make build

# Deploy the functions on AWS
make deploy

# Run integration tests against the API in the cloud
make tests-integ

Load Test

Artillery is used to make 300 requests / second for 10 minutes to our API endpoints. You can run this with the following command:

make tests-load

CloudWatch Logs Insights

Using this CloudWatch Logs Insights query you can analyse the latency of the requests made to the Lambda functions.

The query separates cold starts from other requests and then gives you p50, p90 and p99 percentiles.

filter @type="REPORT"
| fields greatest(@initDuration, 0) + @duration as duration, ispresent(@initDuration) as coldStart
| stats count(*) as count, pct(duration, 50) as p50, pct(duration, 90) as p90, pct(duration, 99) as p99, max(duration) as max by coldStart

Load Test Results

🦀 Getting started with Rust on Lambda

If you want to get started with Rust on Lambda, you can use these cookiecutter templates to setup your project.

👀 With other languages

You can find implementations of this project in other languages here:

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

About

Sample serverless application written in Rust

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 97.2%
  • JavaScript 1.4%
  • Makefile 1.4%