A tiny runtime for handling AWS SQS events in AWS Lambda with:
- Parallel processing: Each SQS record is processed in its own Tokio task
- Partial batch failure support: Automatically handles
PartialBatchFailureresponses when individual records fail - Robust error handling: Classifies and handles different error types (handler errors, task cancellation, panics)
- Observability: Propagates message IDs through tracing spans for better logging and debugging
Add this to your Cargo.toml:
[dependencies]
runo-sqs-lambda-runtime = "0.1.0"
tokio = { version = "1.0", features = ["macros"] }
serde = { version = "1.0", features = ["derive"] }
tracing = "0.1"use runo_sqs_lambda_runtime::{run_in_lambda, Context, Result};
use serde::Deserialize;
#[derive(Deserialize)]
struct Greeter {
pub person: String,
}
async fn sqs_handler(payload: Greeter, context: Context) -> Result<()> {
tracing::info!(
message_id = %context.id,
"Hello, {}!",
payload.person
);
// Your business logic here
// Return Err(error.into()) for failed messages that should be retried
Ok(())
}
#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::init();
run_in_lambda(&sqs_handler).await
}- Type-safe message handling: Generic over your message payload type with automatic JSON deserialization
- Context access: Each handler receives a
Contextwith message ID, headers, and Lambda runtime context - Automatic retries: Failed messages are automatically marked for retry via SQS batch failure responses
- Structured logging: Message IDs are automatically included in tracing spans
- Panic recovery: Task panics are caught and logged, with the message marked for retry
The Context provides:
id: The SQS message IDheaders: Typed access to SQS message attributes viaget()andget_or()lambda_context: The original AWS Lambda context
Your handler should return:
Ok(())for successfully processed messagesErr(error)for messages that should be retried (will be included in batch failure response)
The runtime handles:
- Deserialization errors (message marked for retry)
- Handler errors (message marked for retry)
- Task panics (message marked for retry)
- Task cancellation (message marked for retry)
This project is licensed under the MIT License.