AWS Lambda with Http-Requests and SQS-Events?

#1

I want to use a Rust lambda for SQS-Events as well as for Http-Requests. Is that possible?
In a nutshell, I want something like this:

use aws_lambda_events::event::sqs::SqsEvent;
use lambda_http::{IntoResponse, Request};
use lambda_runtime::{lambda, error::HandlerError, Context};
use serde_derive::{Serialize, Deserialize};
use serde_json::json;

fn main() {
    lambda!(handler)
}

enum Event {
    Http(Request),
    Sqs(SqsEvent),
}

fn handler(e: Event, _: Context) -> Result<impl IntoResponse, HandlerError> {
    match e {
        Event::Http(_) => Ok(json!({
            "message": "Http"
        })),
        Event::Sqs(_) => Ok(json!({
            "message": "Sqs"
        })),
    }
}

But it seems that normal Lambda handlers (from lambda_runtime) must be serializeable and deserializeable but the Http-Handler (from lambda_http) is not. So I’m stuck here. Has anyone tried something like that before?

0 Likes