Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,102 changes: 513 additions & 589 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions hello/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "hello"
version = "0.1.0"
edition = "2018"
edition = "2021"

[dependencies]
tokio = { version = "0.2", features = ["macros"] }
lambda = { git = "https://github.com/awslabs/aws-lambda-rust-runtime/", branch = "master"}
tokio = { version = "1.34.0", features = ["macros", "rt-multi-thread"] }
lambda_runtime = "0.8.3"
serde_json = "1.0"
17 changes: 8 additions & 9 deletions hello/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
use lambda::{handler_fn, Context};
use lambda_runtime::{service_fn, LambdaEvent};
use serde_json::Value;

type Error = Box<dyn std::error::Error + Sync + Send + 'static>;

#[tokio::main]
async fn main() -> Result<(), Error> {
lambda::run(handler_fn(hello)).await?;
lambda_runtime::run(service_fn(hello)).await?;
Ok(())
}

async fn hello(event: Value, _: Context) -> Result<Value, Error> {
Ok(event)
async fn hello(event: LambdaEvent<Value>) -> Result<Value, Error> {
Ok(event.payload)
}

#[cfg(test)]
mod tests {
use super::*;
use lambda_runtime::Context;
use serde_json::json;

#[tokio::test]
async fn hello_handles() {
let event = json!({
"answer": 42
});
let event = LambdaEvent::new(json!({"answer": 42}), Context::default());
assert_eq!(
hello(event.clone(), Context::default()).await.expect("expected Ok(_) value"),
event
hello(event.clone()).await.expect("expected Ok(_) value"),
event.payload
)
}
}
Loading