Skip to main content

fakecloud_lambda/
state.rs

1use chrono::{DateTime, Utc};
2use parking_lot::RwLock;
3use std::collections::HashMap;
4use std::sync::Arc;
5
6#[derive(Debug, Clone)]
7pub struct LambdaFunction {
8    pub function_name: String,
9    pub function_arn: String,
10    pub runtime: String,
11    pub role: String,
12    pub handler: String,
13    pub description: String,
14    pub timeout: i64,
15    pub memory_size: i64,
16    pub code_sha256: String,
17    pub code_size: i64,
18    pub version: String,
19    pub last_modified: DateTime<Utc>,
20    pub tags: HashMap<String, String>,
21    pub environment: HashMap<String, String>,
22    pub architectures: Vec<String>,
23    pub package_type: String,
24}
25
26#[derive(Debug, Clone)]
27pub struct EventSourceMapping {
28    pub uuid: String,
29    pub function_arn: String,
30    pub event_source_arn: String,
31    pub batch_size: i64,
32    pub enabled: bool,
33    pub state: String,
34    pub last_modified: DateTime<Utc>,
35}
36
37/// A recorded Lambda invocation from cross-service delivery.
38#[derive(Debug, Clone)]
39pub struct LambdaInvocation {
40    pub function_arn: String,
41    pub payload: String,
42    pub timestamp: DateTime<Utc>,
43    pub source: String,
44}
45
46pub struct LambdaState {
47    pub account_id: String,
48    pub region: String,
49    pub functions: HashMap<String, LambdaFunction>,
50    pub event_source_mappings: HashMap<String, EventSourceMapping>,
51    /// Recorded invocations from cross-service integrations (SQS, EventBridge, etc.)
52    pub invocations: Vec<LambdaInvocation>,
53}
54
55impl LambdaState {
56    pub fn new(account_id: &str, region: &str) -> Self {
57        Self {
58            account_id: account_id.to_string(),
59            region: region.to_string(),
60            functions: HashMap::new(),
61            event_source_mappings: HashMap::new(),
62            invocations: Vec::new(),
63        }
64    }
65
66    pub fn reset(&mut self) {
67        self.functions.clear();
68        self.event_source_mappings.clear();
69        self.invocations.clear();
70    }
71}
72
73pub type SharedLambdaState = Arc<RwLock<LambdaState>>;