1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
use serde::Deserialize;
/// Request tracing information
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Tracing {
/// The type of tracing exposed to the extension
pub r#type: String,
/// The span value
pub value: String,
}
/// Event received when there is a new Lambda invocation.
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct InvokeEvent {
/// The time that the function times out
pub deadline_ms: u64,
/// The ID assigned to the Lambda request
pub request_id: String,
/// The function's Amazon Resource Name
pub invoked_function_arn: String,
/// The request tracing information
pub tracing: Tracing,
}
/// Event received when a Lambda function shuts down.
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ShutdownEvent {
/// The reason why the function terminates
/// It can be SPINDOWN, TIMEOUT, or FAILURE
pub shutdown_reason: String,
/// The time that the function times out
pub deadline_ms: u64,
}
/// Event that the extension receives in
/// either the INVOKE or SHUTDOWN phase
#[derive(Debug, Deserialize)]
#[serde(rename_all = "UPPERCASE", tag = "eventType")]
pub enum NextEvent {
/// Payload when the event happens in the INVOKE phase
Invoke(InvokeEvent),
/// Payload when the event happens in the SHUTDOWN phase
Shutdown(ShutdownEvent),
}
impl NextEvent {
/// Return whether the event is a [`NextEvent::Invoke`] event or not
pub fn is_invoke(&self) -> bool {
matches!(self, NextEvent::Invoke(_))
}
}
/// Wrapper with information about the next
/// event that the Lambda Runtime is going to process
pub struct LambdaEvent {
/// Next incoming event
pub next: NextEvent,
}
impl LambdaEvent {
pub(crate) fn new(next: NextEvent) -> LambdaEvent {
LambdaEvent { next }
}
}