#[cfg(feature = "lambda")]
use datafold::lambda::{LambdaConfig, LambdaContext, LambdaLogging};
#[cfg(feature = "lambda")]
use datafold::storage::DatabaseConfig;
#[cfg(feature = "lambda")]
use lambda_runtime::{run, service_fn, Error, LambdaEvent};
#[cfg(feature = "lambda")]
use serde_json::{json, Value};
#[cfg(feature = "lambda")]
async fn function_handler(event: LambdaEvent<Value>) -> Result<Value, Error> {
tracing::info!("Received event: {:?}", event.payload);
let node = LambdaContext::node().await?;
let node_id = {
let node_guard = node.lock().await;
node_guard.get_node_id().to_string()
};
tracing::info!("Processing with node: {}", node_id);
Ok(json!({
"statusCode": 200,
"body": {
"message": "Processed successfully",
"node_id": node_id
}
}))
}
#[cfg(feature = "lambda")]
#[tokio::main]
async fn main() -> Result<(), Error> {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
.with_target(false)
.without_time() .init();
tracing::info!("Initializing Lambda context...");
let storage_config = DatabaseConfig::Local {
path: std::env::temp_dir(),
};
let mut config = LambdaConfig::new(storage_config, LambdaLogging::Stdout);
if let Ok(schema_url) = std::env::var("SCHEMA_SERVICE_URL") {
if !schema_url.is_empty() {
config = config.with_schema_service_url(schema_url);
}
}
LambdaContext::init(config)
.await
.map_err(|e| format!("Failed to initialize Lambda context: {}", e))?;
tracing::info!("Lambda initialized successfully");
run(service_fn(function_handler)).await
}
#[cfg(not(feature = "lambda"))]
fn main() {
println!("This example requires the 'lambda' feature flag.");
println!("Run with: cargo run --example lambda_s3_ingestion --features lambda");
println!();
println!("Note: This is an example for AWS Lambda deployment.");
println!("See the documentation in the file for setup instructions.");
}