Skip to content

πŸ¦€ WIP - My go-to patterns for Rust microservices on AWS Lambda

Notifications You must be signed in to change notification settings

mattenarle10/rust-microservice-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

rust-microservice-template πŸ¦€

WIP - extracted from production, still figuring out what else to add

My go-to patterns for Rust microservices on AWS Lambda. Got tired of copying the same boilerplate between services so I extracted what actually works.

What's in here πŸ¦€

  • Cargo workspace - monorepo structure, common crate for shared stuff
  • lambda_http - lighter than Axum/Actix for Lambda
  • DynamoDB singleton - OnceCell pattern, no client recreation per request
  • Dual-mode auth - dev tokens for local, Cognito JWT for prod
  • Cursor pagination - base64 encoded LastEvaluatedKey, works out of the box

Getting started πŸ¦€

cargo check
cargo test
# or build for lambda
cargo lambda build --release

Structure πŸ¦€

β”œβ”€β”€ common/           # shared utilities
β”‚   └── src/
β”‚       β”œβ”€β”€ auth.rs       # dual-mode JWT
β”‚       β”œβ”€β”€ db.rs         # dynamodb singleton
β”‚       β”œβ”€β”€ cors.rs
β”‚       β”œβ”€β”€ health.rs
β”‚       └── pagination.rs
└── services/
    └── example/      # copy this for new services

Dev auth πŸ¦€

curl -H "Authorization: Bearer dev:matt@example.com:user" \
  http://localhost:9000/items

Format: Bearer dev:<email>:<role>

Adding a service πŸ¦€

  1. Copy services/example/
  2. Add to workspace in root Cargo.toml
  3. Implement your handlers

Pairs well with solidjs-fe-template for admin portals.

About

πŸ¦€ WIP - My go-to patterns for Rust microservices on AWS Lambda

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages