Skip to main content

classify_event

Function classify_event 

Source
pub fn classify_event(event: &Value) -> LambdaEvent
Expand description

Classify a raw Lambda event JSON shape.

Heuristic:

  • SQS event JSON has a top-level "Records" array whose entries contain "eventSource": "aws:sqs".
  • HTTP event JSON has one of httpMethod, requestContext.http.method, or routeKey.
  • Anything else is LambdaEvent::Unknown.

Adopter usage for a composite Lambda (HTTP + SQS + EventBridge nightly schedule):

lambda_runtime::run(lambda_runtime::service_fn(
    move |event: lambda_runtime::LambdaEvent<serde_json::Value>| {
        let handler = handler.clone();
        async move {
            let (value, _ctx) = event.into_parts();
            match turul_a2a_aws_lambda::classify_event(&value) {
                turul_a2a_aws_lambda::LambdaEvent::Http => {
                    handler.handle_http_event_value(value).await
                }
                turul_a2a_aws_lambda::LambdaEvent::Sqs => {
                    let sqs = serde_json::from_value(value)?;
                    Ok(serde_json::to_value(handler.handle_sqs(sqs).await)?)
                }
                turul_a2a_aws_lambda::LambdaEvent::Unknown => {
                    // Adopter-owned — the framework does not know
                    // what this event means.
                    run_nightly_audit(/* adopter context */).await
                }
            }
        }
    }
))