#lambda #redis #cargo #local #invoke #amazon-sqs

bin+lib srill

Subscribe Redis and Invoke Lambda with cargo lambda, for Local development

5 releases (1 stable)

Uses new Rust 2024

1.0.0 Sep 6, 2025
0.3.1 Aug 1, 2025
0.2.1 Jun 3, 2025
0.1.0 Jun 2, 2025

#894 in Database interfaces

Download history 243/week @ 2025-10-16 321/week @ 2025-10-23 563/week @ 2025-10-30 714/week @ 2025-11-06 566/week @ 2025-11-13 263/week @ 2025-11-20 579/week @ 2025-11-27 475/week @ 2025-12-04 599/week @ 2025-12-11 495/week @ 2025-12-18 162/week @ 2025-12-25 195/week @ 2026-01-01 470/week @ 2026-01-08 587/week @ 2026-01-15 560/week @ 2026-01-22 599/week @ 2026-01-29

2,266 downloads per month

MIT license

16KB
168 lines

srill

Subscribe Redis and Invoke Lambda with cargo lambda, for Local development.

Features

  • Subscribe to multiple Redis channels simultaneously
  • Invoke different Lambda functions for each channel
  • Support for configuration files (TOML format)

Usage

First, run cargo lambda watch:

cargo lambda watch

Multiple Channels

Start srill with multiple channel-lambda pairs:

srill --channels channel1=lambda-function1,channel2=lambda-function2,channel3=lambda-function3

Configuration File

Create a srill.toml configuration file:

redis_url = "redis://localhost:6379"

[channels]
channel1 = "lambda-function1"
channel2 = "lambda-function2"
channel3 = "lambda-function3"

Then start srill:

srill --config srill.toml

Single Channel Mode

Start srill:

srill <channel name> <lambda binary name>

Publishing Messages

Publishing SQS Events

Publishers should create and publish SQS event JSON:

use redis::Commands;
use srill::events::sqs::{SqsEvent, SqsMessage};
use serde_json;

fn publish_message(conn: &mut redis::Connection) -> Result<(), Box<dyn std::error::Error>> {
    // Customize this event as you like.
    let event = SqsEvent {
        records: vec![SqsMessage {
            body: Some("Test message.".to_string()),
            ..Default::default()
        }],
    };

    let _: () = conn.publish("<channel_name>", &serde_json::to_string(&event)?)?;
    Ok(())
}

Message Format

The Lambda function receives the complete SQS event as published to Redis:

{
    "Records": [
        {
            "messageId": "<uuid-v4>",
            "receiptHandle": "<random string>",
            "body": "Test message.",
            "md5OfBody": "e62f489304eae26e9960977058872c3f",
            "attributes": {
                "ApproximateReceiveCount": "2",
                "SentTimestamp": "1520621625029",
                "SenderId": "sender",
                "ApproximateFirstReceiveTimestamp": "1520621634884"
            },
            "eventSourceARN": "arn:aws:sqs:ap-northeast-1:123456789012:SQSQueue",
            "eventSource": "aws:sqs",
            "awsRegion": "ap-northeast-1",
            "messageAttributes": {
                "Attribute3": {
                    "binaryValue": "MTEwMA==",
                    "stringListValues": ["abc", "123"],
                    "binaryListValues": ["MA==", "MQ==", "MA=="],
                    "dataType": "Binary"
                },
                "Attribute2": {
                    "stringValue": "123",
                    "stringListValues": [],
                    "binaryListValues": ["MQ==", "MA=="],
                    "dataType": "Number"
                },
                "Attribute1": {
                    "stringValue": "AttributeValue1",
                    "stringListValues": [],
                    "binaryListValues": [],
                    "dataType": "String"
                }
            }
        }
    ]
}

Options

  • --redis-url: Redis URL (default: redis://localhost:6379)
  • --channels: Channel-Lambda pairs in format channel1=lambda1,channel2=lambda2
  • --config: Path to TOML configuration file

Examples

# Multiple channels via command line
srill --redis-url redis://localhost:6379 --channels user-events=user-lambda,order-events=order-lambda

# Using configuration file
srill --config ./config/srill.toml

# Single channel
srill my-channel my-lambda

License

MIT

Dependencies

~9–22MB
~252K SLoC