-
Notifications
You must be signed in to change notification settings - Fork 360
/
Copy pathmain.rs
37 lines (32 loc) · 1.09 KB
/
main.rs
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
use lambda_runtime::{service_fn, Diagnostic, Error, LambdaEvent};
use serde::Deserialize;
use thiserror;
#[derive(Deserialize)]
struct Request {}
#[derive(Debug, thiserror::Error)]
pub enum ExecutionError {
#[error("transient database error: {0}")]
DatabaseError(String),
#[error("unexpected error: {0}")]
Unexpected(String),
}
impl From<ExecutionError> for Diagnostic {
fn from(value: ExecutionError) -> Diagnostic {
let (error_type, error_message) = match value {
ExecutionError::DatabaseError(err) => ("Retryable", err.to_string()),
ExecutionError::Unexpected(err) => ("NonRetryable", err.to_string()),
};
Diagnostic {
error_type: error_type.into(),
error_message: error_message.into(),
}
}
}
/// This is the main body for the Lambda function
async fn function_handler(_event: LambdaEvent<Request>) -> Result<(), ExecutionError> {
Err(ExecutionError::Unexpected("ooops".to_string()))
}
#[tokio::main]
async fn main() -> Result<(), Error> {
lambda_runtime::run(service_fn(function_handler)).await
}