From f40461785625d8ac23e7c248367b1d724ef2b5ba Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Fri, 17 Jul 2020 17:37:23 -0400 Subject: [PATCH 01/19] Replace `genawaiter` with `async-stream` (#240) --- Cargo.lock | 97 +++++++++++------------------------------------ lambda/Cargo.toml | 2 +- lambda/src/lib.rs | 13 ++++--- 3 files changed, 30 insertions(+), 82 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 49c98444..5cd113cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,6 +5,25 @@ name = "arc-swap" version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "async-stream" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "async-stream-impl 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "async-stream-impl" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "autocfg" version = "1.0.0" @@ -136,34 +155,6 @@ dependencies = [ "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "genawaiter" -version = "0.99.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "genawaiter-macro 0.99.1 (registry+https://github.com/rust-lang/crates.io-index)", - "genawaiter-proc-macro 0.99.1 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "genawaiter-macro" -version = "0.99.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "genawaiter-proc-macro" -version = "0.99.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro-error 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "h2" version = "0.2.1" @@ -281,9 +272,9 @@ dependencies = [ name = "lambda" version = "0.1.0" dependencies = [ + "async-stream 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "genawaiter 0.99.1 (registry+https://github.com/rust-lang/crates.io-index)", "http 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", "lambda-attributes 0.1.0", @@ -466,30 +457,6 @@ name = "pin-utils" version = "0.1.0-alpha.4" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "proc-macro-error" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro-error-attr 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", - "version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "proc-macro-error-attr" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", - "syn-mid 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "proc-macro-hack" version = "0.5.11" @@ -626,16 +593,6 @@ dependencies = [ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "syn-mid" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "time" version = "0.1.42" @@ -792,11 +749,6 @@ dependencies = [ "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "version_check" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "want" version = "0.3.0" @@ -846,6 +798,8 @@ dependencies = [ [metadata] "checksum arc-swap 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d7b8a9123b8027467bce0099fe556c628a53c8d83df0507084c31e9ba2e39aff" +"checksum async-stream 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "22068c0c19514942eefcfd4daf8976ef1aad84e61539f95cd200c35202f80af5" +"checksum async-stream-impl 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "25f9db3b38af870bf7e5cc649167533b493928e50744e2c30ae350230b414670" "checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" "checksum base64 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "53d1ccbaf7d9ec9537465a97bf19edc1a4e158ecb49fc16178202238c569cc42" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" @@ -864,9 +818,6 @@ dependencies = [ "checksum futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "171be33efae63c2d59e6dbba34186fe0d6394fb378069a76dfd80fdcffd43c16" "checksum futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0bae52d6b29cf440e298856fec3965ee6fa71b06aa7495178615953fd669e5f9" "checksum futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c0d66274fb76985d3c62c886d1da7ac4c0903a8c9f754e8fe0f35a6a6cc39e76" -"checksum genawaiter 0.99.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c86bd0361bcbde39b13475e6e36cb24c329964aa2611be285289d1e4b751c1a0" -"checksum genawaiter-macro 0.99.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b32dfe1fdfc0bbde1f22a5da25355514b5e450c33a6af6770884c8750aedfbc" -"checksum genawaiter-proc-macro 0.99.1 (registry+https://github.com/rust-lang/crates.io-index)" = "784f84eebc366e15251c4a8c3acee82a6a6f427949776ecb88377362a9621738" "checksum h2 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b9433d71e471c1736fd5a61b671fc0b148d7a2992f666c958d03cd8feb3b88d1" "checksum hermit-abi 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "eff2656d88f158ce120947499e971d743c05dbcbed62e5bd2f38f1698bbc3772" "checksum http 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b708cc7f06493459026f53b9a61a7a121a5d1ec6238dee58ea4941132b30156b" @@ -896,8 +847,6 @@ dependencies = [ "checksum pin-project-internal 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "385322a45f2ecf3410c68d2a549a4a2685e8051d0f278e39743ff4e451cb9b3f" "checksum pin-project-lite 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "237844750cfbb86f67afe27eee600dfbbcb6188d734139b534cbfbf4f96792ae" "checksum pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5894c618ce612a3fa23881b152b608bafb8c56cfc22f434a3ba3120b40f7b587" -"checksum proc-macro-error 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "18f33027081eba0a6d8aba6d1b1c3a3be58cbb12106341c2d5759fcd9b5277e7" -"checksum proc-macro-error-attr 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "8a5b4b77fdb63c1eca72173d68d24501c54ab1269409f6b672c85deb18af69de" "checksum proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)" = "ecd45702f76d6d3c75a80564378ae228a85f0b59d2f3ed43c91b4a69eb2ebfc5" "checksum proc-macro-nested 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "369a6ed065f249a159e06c45752c780bda2fb53c995718f9e484d08daa9eb42e" "checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" @@ -915,7 +864,6 @@ dependencies = [ "checksum smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" "checksum socket2 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "e8b74de517221a2cb01a53349cf54182acdc31a074727d3079068448c0676d85" "checksum syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "af6f3550d8dff9ef7dc34d384ac6f107e5d31c8f57d9f28e0081503f547ac8f5" -"checksum syn-mid 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a" "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" "checksum tokio 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8fdd17989496f49cdc57978c96f0c9fe5e4a58a8bddc6813c449a4624f6a030b" "checksum tokio-macros 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f4b1e7ed7d5d4c2af3d999904b0eebe76544897cdbfb2b9684bed2174ab20f7c" @@ -933,7 +881,6 @@ dependencies = [ "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" "checksum url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb" -"checksum version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce" "checksum want 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" diff --git a/lambda/Cargo.toml b/lambda/Cargo.toml index 7acf8cbd..eb718e80 100644 --- a/lambda/Cargo.toml +++ b/lambda/Cargo.toml @@ -20,7 +20,7 @@ tower-service = "0.3" bytes = "0.5" http = "0.2" lambda-attributes = { path = "../lambda-attributes", version = "0.1.0", optional = true} -genawaiter = { version = "0.99", features = ["futures03"] } +async-stream = "0.2" futures = "0.3" tracing = "0.1.13" tracing-futures = "0.2.3" diff --git a/lambda/src/lib.rs b/lambda/src/lib.rs index 4d6b3839..24ef4929 100644 --- a/lambda/src/lib.rs +++ b/lambda/src/lib.rs @@ -36,7 +36,6 @@ pub use crate::types::Context; use client::Client; use futures::stream::{Stream, StreamExt}; -use genawaiter::{sync::gen, yield_}; pub use lambda_attributes::lambda; use serde::{Deserialize, Serialize}; use std::{ @@ -179,17 +178,18 @@ where } fn incoming(client: &Client) -> impl Stream, Error>> + '_ { - gen!({ + async_stream::stream! { loop { let req = NextEventRequest.into_req().expect("Unable to construct request"); - yield_!(client.call(req).await) + let res = client.call(req).await; + yield res; } - }) + } } async fn run_inner( client: &Client, - incoming: impl Stream, Error>> + Unpin, + incoming: impl Stream, Error>>, handler: &mut F, ) -> Result<(), Error> where @@ -198,7 +198,8 @@ where A: for<'de> Deserialize<'de>, B: Serialize, { - let mut incoming = incoming; + tokio::pin!(incoming); + while let Some(event) = incoming.next().await { let event = event?; let (parts, body) = event.into_parts(); From a8ef3c3aa2f401e0054b2069e0fcfcf59c61fecd Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 22 Jul 2020 05:08:55 +0000 Subject: [PATCH 02/19] Log handler errors in runtime. Issue #241 --- Cargo.lock | 666 ++++++++++++++++-------------- lambda/Cargo.toml | 14 +- lambda/examples/error-handling.rs | 110 +++++ lambda/examples/readme.md | 156 +++++++ lambda/src/client.rs | 57 +-- lambda/src/lib.rs | 29 +- 6 files changed, 646 insertions(+), 386 deletions(-) create mode 100644 lambda/examples/error-handling.rs create mode 100644 lambda/examples/readme.md diff --git a/Cargo.lock b/Cargo.lock index 5cd113cd..329fd8fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,7 +2,7 @@ # It is not intended for manual editing. [[package]] name = "arc-swap" -version = "0.4.4" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -11,7 +11,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "async-stream-impl 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -19,9 +19,19 @@ name = "async-stream-impl" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "hermit-abi 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -31,7 +41,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "base64" -version = "0.12.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -41,7 +51,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bytes" -version = "0.5.4" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -49,14 +59,34 @@ name = "cfg-if" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "chrono" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-integer 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "colored" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "dtoa" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "fnv" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -75,120 +105,132 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "futures" -version = "0.3.1" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures-channel 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-executor 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-io 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-channel 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-executor 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-io 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-task 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "futures-channel" -version = "0.3.1" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "futures-core" -version = "0.3.1" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "futures-executor" -version = "0.3.1" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-task 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "futures-io" -version = "0.3.1" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "futures-macro" -version = "0.3.1" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.5.16 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "futures-sink" -version = "0.3.1" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "futures-task" -version = "0.3.1" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "once_cell 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "futures-util" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "futures-channel 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-io 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-macro 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro-nested 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures-channel 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-io 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-macro 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-task 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "pin-project 0.4.22 (registry+https://github.com/rust-lang/crates.io-index)", + "pin-utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.5.16 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-nested 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "h2" -version = "0.2.1" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", - "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "http 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "indexmap 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "fnv 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "indexmap 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-util 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tracing 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "hashbrown" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "hermit-abi" -version = "0.1.6" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "http" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", - "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "itoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "fnv 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -196,8 +238,8 @@ name = "http-body" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", - "http 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -207,24 +249,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "hyper" -version = "0.13.1" +version = "0.13.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-channel 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "h2 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "http 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-channel 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "h2 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "http-body 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "itoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "pin-project 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "pin-project 0.4.22 (registry+https://github.com/rust-lang/crates.io-index)", + "socket2 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", "tower-service 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tracing 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "want 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -235,15 +277,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "indexmap" -version = "1.3.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hashbrown 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -251,12 +294,12 @@ name = "iovec" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "itoa" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -273,18 +316,18 @@ name = "lambda" version = "0.1.0" dependencies = [ "async-stream 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "http 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hyper 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.13.7 (registry+https://github.com/rust-lang/crates.io-index)", "lambda-attributes 0.1.0", - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)", + "simple-error 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "simple_logger 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", "tower-service 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-error 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-futures 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -292,25 +335,25 @@ name = "lambda-attributes" version = "0.1.0" dependencies = [ "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "lambda_http" version = "0.2.0-beta.1" dependencies = [ - "base64 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", - "http 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "base64 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "lambda 0.1.0", "lambda-attributes 0.1.0", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "maplit 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)", "serde_urlencoded 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -320,12 +363,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.66" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "log" -version = "0.4.8" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -343,12 +386,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "memchr" -version = "2.3.0" +version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "mio" -version = "0.6.21" +version = "0.6.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -356,33 +399,33 @@ dependencies = [ "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", + "net2 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "mio-named-pipes" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)", - "miow 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.22 (registry+https://github.com/rust-lang/crates.io-index)", + "miow 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "mio-uds" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.22 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -391,39 +434,61 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", + "net2 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "miow" -version = "0.3.3" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "socket2 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "socket2 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "net2" -version = "0.2.33" +version = "0.2.34" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-integer" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-traits" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num_cpus" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "hermit-abi 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", + "hermit-abi 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "once_cell" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "percent-encoding" version = "2.1.0" @@ -431,45 +496,40 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "pin-project" -version = "0.4.8" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "pin-project-internal 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "pin-project-internal 0.4.22 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "pin-project-internal" -version = "0.4.8" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "pin-project-lite" -version = "0.1.4" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "pin-utils" -version = "0.1.0-alpha.4" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "proc-macro-hack" -version = "0.5.11" +version = "0.5.16" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", -] [[package]] name = "proc-macro-nested" -version = "0.1.3" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -482,56 +542,56 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.8" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "quote" -version = "1.0.2" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_syscall" -version = "0.1.56" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "ryu" -version = "1.0.2" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" -version = "1.0.104" +version = "1.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_derive" -version = "1.0.104" +version = "1.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_json" -version = "1.0.45" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "itoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "ryu 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -539,27 +599,36 @@ name = "serde_urlencoded" version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "dtoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "itoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", + "dtoa 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "sharded-slab" -version = "0.0.9" +name = "signal-hook-registry" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "arc-swap 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "signal-hook-registry" -version = "1.2.0" +name = "simple-error" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "simple_logger" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "arc-swap 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", + "atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", + "colored 1.9.3 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -567,86 +636,85 @@ name = "slab" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "smallvec" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "socket2" -version = "0.3.11" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "syn" -version = "1.0.14" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "time" -version = "0.1.42" +version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tinyvec" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "tokio" -version = "0.2.11" +version = "0.2.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", - "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "fnv 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)", - "mio-named-pipes 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "pin-project-lite 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.22 (registry+https://github.com/rust-lang/crates.io-index)", + "mio-named-pipes 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "mio-uds 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.13.0 (registry+https://github.com/rust-lang/crates.io-index)", + "pin-project-lite 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "signal-hook-registry 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-macros 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-macros 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-macros" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-util" -version = "0.2.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "pin-project-lite 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "pin-project-lite 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -656,61 +724,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "tracing" -version = "0.1.13" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-attributes 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "tracing-attributes" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "tracing-core 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tracing-core" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "tracing-error" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "tracing 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-subscriber 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "tracing-futures" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "pin-project 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "tracing-subscriber" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "sharded-slab 0.0.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "try-lock" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -723,10 +755,10 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tinyvec 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -736,7 +768,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "unicode-xid" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -754,8 +786,8 @@ name = "want" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "try-lock 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -765,7 +797,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "winapi" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -797,93 +829,97 @@ dependencies = [ ] [metadata] -"checksum arc-swap 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d7b8a9123b8027467bce0099fe556c628a53c8d83df0507084c31e9ba2e39aff" +"checksum arc-swap 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "4d25d88fd6b8041580a654f9d0c581a047baee2b3efee13275f2fc392fc75034" "checksum async-stream 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "22068c0c19514942eefcfd4daf8976ef1aad84e61539f95cd200c35202f80af5" "checksum async-stream-impl 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "25f9db3b38af870bf7e5cc649167533b493928e50744e2c30ae350230b414670" +"checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" "checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" -"checksum base64 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "53d1ccbaf7d9ec9537465a97bf19edc1a4e158ecb49fc16178202238c569cc42" +"checksum base64 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" -"checksum bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "130aac562c0dd69c56b3b1cc8ffd2e17be31d0b6c25b61c96b76231aa23e39e1" +"checksum bytes 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" -"checksum dtoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "4358a9e11b9a09cf52383b451b49a169e8d797b68aa02301ff586d70d9661ea3" -"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" +"checksum chrono 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)" = "c74d84029116787153e02106bf53e66828452a4b325cc8652b788b5967c0a0b6" +"checksum colored 1.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59" +"checksum dtoa 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b" +"checksum fnv 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -"checksum futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b6f16056ecbb57525ff698bb955162d0cd03bee84e6241c27ff75c08d8ca5987" -"checksum futures-channel 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fcae98ca17d102fd8a3603727b9259fcf7fa4239b603d2142926189bc8999b86" -"checksum futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "79564c427afefab1dfb3298535b21eda083ef7935b4f0ecbfcb121f0aec10866" -"checksum futures-executor 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1e274736563f686a837a0568b478bdabfeaec2dca794b5649b04e2fe1627c231" -"checksum futures-io 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e676577d229e70952ab25f3945795ba5b16d63ca794ca9d2c860e5595d20b5ff" -"checksum futures-macro 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "52e7c56c15537adb4f76d0b7a76ad131cb4d2f4f32d3b0bcabcbe1c7c5e87764" -"checksum futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "171be33efae63c2d59e6dbba34186fe0d6394fb378069a76dfd80fdcffd43c16" -"checksum futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0bae52d6b29cf440e298856fec3965ee6fa71b06aa7495178615953fd669e5f9" -"checksum futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c0d66274fb76985d3c62c886d1da7ac4c0903a8c9f754e8fe0f35a6a6cc39e76" -"checksum h2 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b9433d71e471c1736fd5a61b671fc0b148d7a2992f666c958d03cd8feb3b88d1" -"checksum hermit-abi 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "eff2656d88f158ce120947499e971d743c05dbcbed62e5bd2f38f1698bbc3772" -"checksum http 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b708cc7f06493459026f53b9a61a7a121a5d1ec6238dee58ea4941132b30156b" +"checksum futures 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1e05b85ec287aac0dc34db7d4a569323df697f9c55b99b15d6b4ef8cde49f613" +"checksum futures-channel 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f366ad74c28cca6ba456d95e6422883cfb4b252a83bed929c83abfdbbf2967d5" +"checksum futures-core 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399" +"checksum futures-executor 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "10d6bb888be1153d3abeb9006b11b02cf5e9b209fda28693c31ae1e4e012e314" +"checksum futures-io 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "de27142b013a8e869c14957e6d2edeef89e97c289e69d042ee3a49acd8b51789" +"checksum futures-macro 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d0b5a30a4328ab5473878237c447333c093297bded83a4983d10f4deea240d39" +"checksum futures-sink 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3f2032893cb734c7a05d85ce0cc8b8c4075278e93b24b66f9de99d6eb0fa8acc" +"checksum futures-task 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626" +"checksum futures-util 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6" +"checksum h2 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "993f9e0baeed60001cf565546b0d3dbe6a6ad23f2bd31644a133c641eccf6d53" +"checksum hashbrown 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "34f595585f103464d8d2f6e9864682d74c1601fed5e07d62b1c9058dba8246fb" +"checksum hermit-abi 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9" +"checksum http 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "28d569972648b2c512421b5f2a405ad6ac9666547189d0c5477a3f200f3e02f9" "checksum http-body 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" "checksum httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" -"checksum hyper 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8bf49cfb32edee45d890537d9057d1b02ed55f53b7b6a30bae83a38c9231749e" +"checksum hyper 0.13.7 (registry+https://github.com/rust-lang/crates.io-index)" = "3e68a8dd9716185d9e64ea473ea6ef63529252e3e27623295a0378a19665d5eb" "checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" -"checksum indexmap 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b54058f0a6ff80b6803da8faf8997cde53872b38f4023728f6830b06cd3c0dc" +"checksum indexmap 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b88cd59ee5f71fea89a62248fc8f387d44400cefe05ef548466d61ced9029a7" "checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -"checksum itoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e" +"checksum itoa 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -"checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" -"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" +"checksum libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)" = "bd7d4bd64732af4bf3a67f367c27df8520ad7e230c5817b8ff485864d80242b9" +"checksum log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" "checksum maplit 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" -"checksum memchr 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3197e20c7edb283f87c071ddfc7a2cca8f8e0b888c242959846a6fce03c72223" -"checksum mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)" = "302dec22bcf6bae6dfb69c647187f4b4d0fb6f535521f7bc022430ce8e12008f" -"checksum mio-named-pipes 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f5e374eff525ce1c5b7687c4cef63943e7686524a387933ad27ca7ec43779cb3" -"checksum mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125" +"checksum memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" +"checksum mio 0.6.22 (registry+https://github.com/rust-lang/crates.io-index)" = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430" +"checksum mio-named-pipes 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "0840c1c50fd55e521b247f949c241c9997709f23bd7f023b9762cd561e935656" +"checksum mio-uds 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" -"checksum miow 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "396aa0f2003d7df8395cb93e09871561ccc3e785f0acb369170e8cc74ddf9226" -"checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" -"checksum num_cpus 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "46203554f085ff89c235cd12f7075f3233af9b11ed7c9e16dfe2560d03313ce6" +"checksum miow 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "07b88fb9795d4d36d62a012dfbf49a8f5cf12751f36d31a9dbe66d528e58979e" +"checksum net2 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)" = "2ba7c918ac76704fb42afcbbb43891e72731f3dcca3bef2a19786297baf14af7" +"checksum num-integer 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" +"checksum num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)" = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" +"checksum num_cpus 1.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +"checksum once_cell 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" "checksum percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" -"checksum pin-project 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7804a463a8d9572f13453c516a5faea534a2403d7ced2f0c7e100eeff072772c" -"checksum pin-project-internal 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "385322a45f2ecf3410c68d2a549a4a2685e8051d0f278e39743ff4e451cb9b3f" -"checksum pin-project-lite 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "237844750cfbb86f67afe27eee600dfbbcb6188d734139b534cbfbf4f96792ae" -"checksum pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5894c618ce612a3fa23881b152b608bafb8c56cfc22f434a3ba3120b40f7b587" -"checksum proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)" = "ecd45702f76d6d3c75a80564378ae228a85f0b59d2f3ed43c91b4a69eb2ebfc5" -"checksum proc-macro-nested 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "369a6ed065f249a159e06c45752c780bda2fb53c995718f9e484d08daa9eb42e" +"checksum pin-project 0.4.22 (registry+https://github.com/rust-lang/crates.io-index)" = "12e3a6cdbfe94a5e4572812a0201f8c0ed98c1c452c7b8563ce2276988ef9c17" +"checksum pin-project-internal 0.4.22 (registry+https://github.com/rust-lang/crates.io-index)" = "6a0ffd45cf79d88737d7cc85bfd5d2894bee1139b356e616fe85dc389c61aaf7" +"checksum pin-project-lite 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "282adbf10f2698a7a77f8e983a74b2d18176c19a7fd32a45446139ae7b02b715" +"checksum pin-utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +"checksum proc-macro-hack 0.5.16 (registry+https://github.com/rust-lang/crates.io-index)" = "7e0456befd48169b9f13ef0f0ad46d492cf9d2dbb918bcf38e01eed4ce3ec5e4" +"checksum proc-macro-nested 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a" "checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" -"checksum proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3acb317c6ff86a4e579dfa00fc5e6cca91ecbb4e7eb2df0468805b674eb88548" -"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" -"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" -"checksum ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bfa8506c1de11c9c4e4c38863ccbe02a305c8188e85a05a784c9e11e1c3910c8" -"checksum serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" -"checksum serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" -"checksum serde_json 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)" = "eab8f15f15d6c41a154c1b128a22f2dfabe350ef53c40953d84e36155c91192b" +"checksum proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)" = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12" +"checksum quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +"checksum redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)" = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" +"checksum ryu 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +"checksum serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)" = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3" +"checksum serde_derive 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)" = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e" +"checksum serde_json 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)" = "3433e879a558dde8b5e8feb2a04899cf34fdde1fafb894687e52105fc1162ac3" "checksum serde_urlencoded 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97" -"checksum sharded-slab 0.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "06d5a3f5166fb5b42a5439f2eee8b9de149e235961e3eb21c5808fc3ea17ff3e" "checksum signal-hook-registry 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94f478ede9f64724c5d173d7bb56099ec3e2d9fc2774aac65d34b8b890405f41" +"checksum simple-error 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "339844c9af2d844b9230bb28e8f819a7790cbf20a29b5cbd2b59916a03a1ef51" +"checksum simple_logger 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fea0c4611f32f4c2bac73754f22dca1f57e6c1945e0590dae4e5f2a077b92367" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" -"checksum smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" -"checksum socket2 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "e8b74de517221a2cb01a53349cf54182acdc31a074727d3079068448c0676d85" -"checksum syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "af6f3550d8dff9ef7dc34d384ac6f107e5d31c8f57d9f28e0081503f547ac8f5" -"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" -"checksum tokio 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8fdd17989496f49cdc57978c96f0c9fe5e4a58a8bddc6813c449a4624f6a030b" -"checksum tokio-macros 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f4b1e7ed7d5d4c2af3d999904b0eebe76544897cdbfb2b9684bed2174ab20f7c" -"checksum tokio-util 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "571da51182ec208780505a32528fc5512a8fe1443ab960b3f2f3ef093cd16930" +"checksum socket2 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)" = "03088793f677dce356f3ccc2edb1b314ad191ab702a5de3faf49304f7e104918" +"checksum syn 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)" = "fb7f4c519df8c117855e19dd8cc851e89eb746fe7a73f0157e0d95fdec5369b0" +"checksum time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" +"checksum tinyvec 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "53953d2d3a5ad81d9f844a32f14ebb121f50b650cd59d0ee2a07cf13c617efed" +"checksum tokio 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)" = "5d34ca54d84bf2b5b4d7d31e901a8464f7b60ac145a284fba25ceb801f2ddccd" +"checksum tokio-macros 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f0c3acc6aa564495a0f2e1d59fab677cd7f81a19994cfc7f3ad0e64301560389" +"checksum tokio-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" "checksum tower-service 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" -"checksum tracing 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1721cc8cf7d770cc4257872507180f35a4797272f5962f24c806af9e7faf52ab" -"checksum tracing-attributes 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "7fbad39da2f9af1cae3016339ad7f2c7a9e870f12e8fd04c4fd7ef35b30c0d2b" -"checksum tracing-core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0aa83a9a47081cd522c09c81b31aec2c9273424976f922ad61c053b58350b715" -"checksum tracing-error 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d7c0b83d4a500748fa5879461652b361edf5c9d51ede2a2ac03875ca185e24" -"checksum tracing-futures 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ab7bb6f14721aa00656086e9335d363c5c8747bae02ebe32ea2c7dece5689b4c" -"checksum tracing-subscriber 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1d53c40489aa69c9aed21ff483f26886ca8403df33bdc2d2f87c60c1617826d2" -"checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" +"checksum tracing 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "c2e2a2de6b0d5cbb13fc21193a2296888eaab62b6044479aafb3c54c01c29fcd" +"checksum tracing-core 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "94ae75f0d28ae10786f3b1895c55fe72e79928fd5ccdebb5438c75e93fec178f" +"checksum try-lock 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" -"checksum unicode-normalization 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "5479532badd04e128284890390c1e876ef7a993d0570b3597ae43dfa1d59afa4" +"checksum unicode-normalization 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6fb19cf769fa8c6a80a162df694621ebeb4dafb606470b2b2fce0be40a98a977" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" -"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +"checksum unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" "checksum url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb" "checksum want 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" +"checksum winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/lambda/Cargo.toml b/lambda/Cargo.toml index eb718e80..5e504c85 100644 --- a/lambda/Cargo.toml +++ b/lambda/Cargo.toml @@ -6,9 +6,7 @@ description = "AWS Lambda Runtime." edition = "2018" [features] -# no features by default -default = ["simulated", "derive"] -simulated = [] +default = ["derive"] # `derive` is commonly used, so is enabled by default derive = ["lambda-attributes"] [dependencies] @@ -22,6 +20,10 @@ http = "0.2" lambda-attributes = { path = "../lambda-attributes", version = "0.1.0", optional = true} async-stream = "0.2" futures = "0.3" -tracing = "0.1.13" -tracing-futures = "0.2.3" -tracing-error = "0.1.2" +log = "0.4" + + +[dev-dependencies] +# used in some of the examples +simple-error = "0.2" +simple_logger = "1.6" diff --git a/lambda/examples/error-handling.rs b/lambda/examples/error-handling.rs new file mode 100644 index 00000000..2e2799ea --- /dev/null +++ b/lambda/examples/error-handling.rs @@ -0,0 +1,110 @@ +/// See https://github.com/awslabs/aws-lambda-rust-runtime for more info on Rust runtime for AWS Lambda +use lambda::handler_fn; +use serde::{Deserialize, Serialize}; +use serde_json::{json, Value}; +use simple_logger; +use simple_error; +use std::fs::File; + + +/// A shorthand for `Box` type required by aws-lambda-rust-runtime. +pub type Error = Box; + +#[derive(Debug, Serialize)] +struct CustomError { + is_authenticated: bool, + req_id: String, + msg: String, +} + +impl std::error::Error for CustomError { + // this implementation required `Debug` and `Display` traits +} + +impl std::fmt::Display for CustomError { + /// Display the error struct as a JSON string + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let err_as_json = json!(self).to_string(); + write!(f, "{}", err_as_json) + } +} + +/// The entry point called by aws-lambda-rust-runtime client for every new Lambda request. +#[tokio::main] +async fn main() -> Result<(), Error> { + simple_logger::init_with_level(log::Level::Debug)?; // Note, this can only be called once! + + // call the actual handler of the request + let func = handler_fn(func); + lambda::run(func).await?; + Ok(()) +} + +/// The actual handler of the Lambda request. +pub(crate) async fn func(event: Value, ctx: lambda::Context) -> Result { + // convert the JSON request to a struct + let req = serde_json::from_value::(event); + + // check if the conversion succeeded and what action was requested + match req { + Err(e) => { + // conversion from JSON to `Request` struct failed + // return serde_json error + return Err(Box::new(e)); + } + Ok(v) if v.event_type == EventType::SimpleError => { + // generate a simple text message error using `simple_error` crate + return Err(Box::new(simple_error::SimpleError::new( + "A simple error as requested!", + ))); + } + Ok(v) if v.event_type == EventType::CustomError => { + // generate a custom error using our own structure + let cust_err = CustomError { + is_authenticated: ctx.identity.is_some(), + req_id: ctx.request_id, + msg: "A custom error as requested!".into(), + }; + return Err(Box::new(cust_err)); + } + Ok(v) if v.event_type == EventType::ExternalError => { + // try to open a non-existent file to get an error and propagate it with `?` + let _file = File::open("non-existent-file.txt")?; + + // it should never execute past the above line + panic!(); + } + Ok(_) => { + // generate and return an OK response in JSON format + let resp = Response { + req_id: ctx.request_id, + msg: "OK".into(), + }; + + return Ok(json!(resp)); + } + } +} + +/// A simple Lambda response structure. +#[derive(Serialize)] +struct Response { + req_id: String, + msg: String, +} + +/// A simple Lambda request structure with just one field +/// that tells the Lambda what is expected of it. +#[derive(Deserialize)] +struct Request { + event_type: EventType, +} + +/// Event types that tell our Lambda what to do do. +#[derive(Deserialize, PartialEq)] +enum EventType { + Response, + ExternalError, + SimpleError, + CustomError, +} diff --git a/lambda/examples/readme.md b/lambda/examples/readme.md new file mode 100644 index 00000000..43094e22 --- /dev/null +++ b/lambda/examples/readme.md @@ -0,0 +1,156 @@ + +## How to compile and run the examples + +1. Compile the example you want to run + +``` +cargo build --release --target x86_64-unknown-linux-musl --example error-handling +``` +2. Prepare the package +``` +cp ./target/x86_64-unknown-linux-musl/release/examples/error-handling ./bootstrap && zip lambda.zip bootstrap && rm bootstrap +``` +3. Upload to AWS Lambda +``` +aws lambda update-function-code --region us-east-1 --function-name ReturnValue --zip-file fileb://lambda.zip +``` +_Remember to replace the names and IDs with your own values._ + + +## Error handling examples for aws-lambda-rust-runtime + +#### Error logging by the runtime + +Errors are logged by the runtime only if `log` is initialised by the handler. +These examples use `simple_logger`, but you can use any other provider that works with `log`. +``` +simple_logger::init_with_level(log::Level::Debug)?; +``` + +#### Sample log output + +The following input/output examples correspond to different `match` arms in the handler of `error-handling.rs`. + +### Invalid JSON input + +Test input: +```json +{ + "event_type": "WrongType" +} +``` + +Lambda output: +``` +{ + "errorType": "alloc::boxed::Box", + "errorMessage": "unknown variant `WrongType`, expected one of `Response`, `ExternalError`, `SimpleError`, `CustomError`" +} +``` + +CloudWatch records: +``` +START RequestId: b98e07c6-e2ba-4ca6-9968-d0b94729ddba Version: $LATEST +2020-07-21 04:28:52,630 ERROR [lambda] unknown variant `WrongType`, expected one of `Response`, `ExternalError`, `SimpleError`, `CustomError` +END RequestId: b98e07c6-e2ba-4ca6-9968-d0b94729ddba +REPORT RequestId: b98e07c6-e2ba-4ca6-9968-d0b94729ddba Duration: 2.06 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 28 MB Init Duration: 33.67 ms +``` + +### A simple text-only error + +Test input: +```json +{ + "event_type": "SimpleError" +} +``` + +Lambda output: +``` +{ + "errorType": "alloc::boxed::Box", + "errorMessage": "A simple error as requested!" +} +``` + +CloudWatch records: +``` +START RequestId: 77c66dbf-bd60-4f77-8453-682d0bceba91 Version: $LATEST +2020-07-21 04:35:28,044 ERROR [lambda] A simple error as requested! +END RequestId: 77c66dbf-bd60-4f77-8453-682d0bceba91 +REPORT RequestId: 77c66dbf-bd60-4f77-8453-682d0bceba91 Duration: 0.98 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 28 MB +``` + +### A custom error with JSON output for Display trait + +Test input: +```json +{ + "event_type": "CustomError" +} +``` + +Lambda output: +``` +{ + "errorType": "alloc::boxed::Box", + "errorMessage": "{\"is_authenticated\":false,\"msg\":\"A custom error as requested!\",\"req_id\":\"b46b0588-1383-4224-bc7a-42b0d61930c1\"}" +} +``` + +CloudWatch records: +``` +START RequestId: b46b0588-1383-4224-bc7a-42b0d61930c1 Version: $LATEST +2020-07-21 04:39:00,133 ERROR [lambda] {"is_authenticated":false,"msg":"A custom error as requested!","req_id":"b46b0588-1383-4224-bc7a-42b0d61930c1"} +END RequestId: b46b0588-1383-4224-bc7a-42b0d61930c1 +REPORT RequestId: b46b0588-1383-4224-bc7a-42b0d61930c1 Duration: 0.91 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 29 MB +``` + +### A 3rd party error from _std::fs::File::open_ + +Test input: +```json +{ + "event_type": "ExternalError" +} +``` + +Lambda output: +``` +{ + "errorType": "alloc::boxed::Box", + "errorMessage": "No such file or directory (os error 2)" +} +``` + +CloudWatch records: +``` +START RequestId: 893d24e5-cb79-4f6f-bae0-36304c62e9da Version: $LATEST +2020-07-21 04:43:56,254 ERROR [lambda] No such file or directory (os error 2) +END RequestId: 893d24e5-cb79-4f6f-bae0-36304c62e9da +REPORT RequestId: 893d24e5-cb79-4f6f-bae0-36304c62e9da Duration: 1.15 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 29 MB +``` + +### A response to a successful Lambda execution + +Test input: +```json +{ + "event_type": "Response" +} +``` + +Lambda output: +``` +{ + "msg": "OK", + "req_id": "9752a3ad-6566-44e4-aafd-74db1fd4f361" +} +``` + +CloudWatch records: +``` +START RequestId: 9752a3ad-6566-44e4-aafd-74db1fd4f361 Version: $LATEST +END RequestId: 9752a3ad-6566-44e4-aafd-74db1fd4f361 +REPORT RequestId: 9752a3ad-6566-44e4-aafd-74db1fd4f361 Duration: 0.89 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 29 MB +``` \ No newline at end of file diff --git a/lambda/src/client.rs b/lambda/src/client.rs index 64313ebf..5a020d73 100644 --- a/lambda/src/client.rs +++ b/lambda/src/client.rs @@ -7,6 +7,7 @@ use http::{ HeaderValue, Method, Request, Response, StatusCode, Uri, }; use hyper::{client::HttpConnector, server::conn::Http, service::service_fn, Body}; +use log::{error, info}; use serde_json::json; use std::convert::TryFrom; use tokio::{ @@ -14,9 +15,7 @@ use tokio::{ select, sync::oneshot, }; -use tracing::{error, info, instrument}; -#[instrument] async fn hello(req: Request) -> Result, Error> { Ok(Response::new(Body::from("hello"))) } @@ -38,7 +37,6 @@ async fn handle_incoming(req: Request) -> Result, Error> { } } -#[instrument(skip(io, rx))] async fn handle(io: I, rx: oneshot::Receiver<()>) -> Result<(), hyper::error::Error> where I: AsyncRead + AsyncWrite + Unpin + 'static, @@ -53,7 +51,7 @@ where match res { Ok(()) => return Ok(()), Err(e) => { - error!(message = "Got error serving connection", e = %e); + error!("Got error serving connection {}", e); return Err(e); } } @@ -275,55 +273,4 @@ mod endpoint_tests { Err(_) => unreachable!("This branch shouldn't be reachable"), } } - - // #[tokio::test] - // async fn run_end_to_end() -> Result<(), Error> { - // use serde_json::Value; - - // let (client, server) = crate::simulated::chan(); - - // let (tx, rx) = sync::oneshot::channel(); - // let server = tokio::spawn(async move { handle(server, rx) }); - - // async fn handler(s: Value) -> Result { - // INVOCATION_CTX.with(|_ctx| {}); - // Ok(s) - // } - // let handler = handler_fn(handler); - // let client = tokio::spawn(async move { - // run_simulated(handler, &url).await?; - // Ok::<(), Error>(()) - // }); - // race!(client, server); - // Ok(()) - // } - - // #[tokio::test] - // async fn test_stream_handler() -> Result<(), Error> { - // let (client, server) = crate::simulated::chan(); - // let req = Request::builder() - // .method(Method::GET) - // .uri("http://httpbin.org") - // .body(Body::empty()) - // .expect("Can't build request"); - - // let conn = SimulatedConnector { inner: client }; - // let client = hyper::Client::builder().build(conn); - - // let (tx, rx) = sync::oneshot::channel(); - // let server = tokio::spawn(async { - // handle(server, rx).await.expect("Unable to handle request"); - // }); - - // let rsp = client.request(req).await.expect("Unable to send request"); - // assert_eq!(rsp.status(), http::StatusCode::OK); - - // // shutdown server - // tx.send(()).expect("Receiver has been dropped"); - // match server.await { - // Ok(_) => Ok(()), - // Err(e) if e.is_panic() => return Err::<(), anyhow::Error>(e.into()), - // Err(_) => unreachable!("This branch shouldn't be reachable"), - // } - // } } diff --git a/lambda/src/lib.rs b/lambda/src/lib.rs index 24ef4929..e3e8d102 100644 --- a/lambda/src/lib.rs +++ b/lambda/src/lib.rs @@ -37,6 +37,7 @@ pub use crate::types::Context; use client::Client; use futures::stream::{Stream, StreamExt}; pub use lambda_attributes::lambda; +use log::error; use serde::{Deserialize, Serialize}; use std::{ convert::{TryFrom, TryInto}, @@ -146,7 +147,7 @@ where pub async fn run(handler: F) -> Result<(), Error> where F: Handler, - >::Error: fmt::Debug, + >::Error: fmt::Display, A: for<'de> Deserialize<'de>, B: Serialize, { @@ -164,7 +165,7 @@ where pub async fn run_simulated(handler: F, url: &str) -> Result<(), Error> where F: Handler, - >::Error: fmt::Debug, + >::Error: fmt::Display, A: for<'de> Deserialize<'de>, B: Serialize, { @@ -194,7 +195,7 @@ async fn run_inner( ) -> Result<(), Error> where F: Handler, - >::Error: fmt::Debug, + >::Error: fmt::Display, A: for<'de> Deserialize<'de>, B: Serialize, { @@ -213,14 +214,17 @@ where let req = match f.await { Ok(res) => EventCompletionRequest { request_id, body: res }.into_req()?, - Err(e) => EventErrorRequest { - request_id, - diagnostic: Diagnostic { - error_message: format!("{:?}", e), - error_type: type_name_of_val(e).to_owned(), - }, + Err(e) => { + error!("{}", e); + EventErrorRequest { + request_id, + diagnostic: Diagnostic { + error_message: format!("{}", e), + error_type: type_name_of_val(e).to_owned(), + }, + } + .into_req()? } - .into_req()?, }; client.call(req).await?; } @@ -228,6 +232,11 @@ where Ok(()) } +/// Returns the name of as a slice, but it is always the same +/// value for all errors: +/// ``` +/// "alloc::boxed::Box" +/// ``` fn type_name_of_val(_: T) -> &'static str { std::any::type_name::() } From afb2b79bba087fefd519590f0a0c9e730acfb54b Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 22 Jul 2020 10:05:38 +0000 Subject: [PATCH 03/19] Added basic.rs example, comments to other examples --- Cargo.lock | 1 + lambda/Cargo.toml | 1 + lambda/examples/basic.rs | 57 +++++++++++++++++++++++++++++++++++++++ lambda/examples/hello.rs | 4 +++ lambda/examples/readme.md | 2 +- 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 lambda/examples/basic.rs diff --git a/Cargo.lock b/Cargo.lock index 329fd8fe..a0468d05 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -323,6 +323,7 @@ dependencies = [ "lambda-attributes 0.1.0", "log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)", "simple-error 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "simple_logger 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/lambda/Cargo.toml b/lambda/Cargo.toml index 5e504c85..10d33266 100644 --- a/lambda/Cargo.toml +++ b/lambda/Cargo.toml @@ -27,3 +27,4 @@ log = "0.4" # used in some of the examples simple-error = "0.2" simple_logger = "1.6" +serde_derive = "1.0" diff --git a/lambda/examples/basic.rs b/lambda/examples/basic.rs new file mode 100644 index 00000000..e132b53f --- /dev/null +++ b/lambda/examples/basic.rs @@ -0,0 +1,57 @@ +use lambda::{handler_fn, Context}; +use serde::{Deserialize, Serialize}; +use serde_json::{json, Value}; +use simple_logger; + +/// A shorthand for `Box` +/// type required by aws-lambda-rust-runtime. +pub type Error = Box; + +#[tokio::main] +async fn main() -> Result<(), Error> { + // required to enable CloudWatch error logging by the runtime + // can be replaced with any other method of initializing `log` + simple_logger::init_with_level(log::Level::Info)?; + + let func = handler_fn(my_handler); + lambda::run(func).await?; + Ok(()) +} + +pub(crate) async fn my_handler(event: Value, ctx: Context) -> Result { + // extract some useful info from the request + let command = match serde_json::from_value::(event) { + Err(e) => { + return Err(Box::new(e)); + } + Ok(v) => v.command, + }; + + // prepare the response + let resp = Response { + req_id: ctx.request_id, + msg: format!("Command {} executed.", command), + }; + + // return `Response` as JSON + Ok(json!(resp)) +} + +/// This is a made up example of what a response structure may look like. +/// There is no restriction on what it can be. The runtime requires responses +/// to be serialized into `serde_json::Value`. The runtime pays no attention +/// to the contents of the response payload. +#[derive(Serialize)] +struct Response { + req_id: String, + msg: String, +} + +/// This is also a made up example. Requests come into the runtime as unicode +/// strings and are converted into `serde_json::Value`, which can map to your +/// own structures. The runtime pays no attention to the +/// contents of the request payload. +#[derive(Deserialize)] +struct Request { + command: String, +} diff --git a/lambda/examples/hello.rs b/lambda/examples/hello.rs index 99472874..090ab34d 100644 --- a/lambda/examples/hello.rs +++ b/lambda/examples/hello.rs @@ -8,3 +8,7 @@ type Error = Box; async fn main(event: Value, _: Context) -> Result { Ok(event) } + +// #[lambda] attribute removes the need for boilerplate code +// required by `lambda::run(func).await?` demonstrated in other +// examples. diff --git a/lambda/examples/readme.md b/lambda/examples/readme.md index 43094e22..4074f366 100644 --- a/lambda/examples/readme.md +++ b/lambda/examples/readme.md @@ -12,7 +12,7 @@ cp ./target/x86_64-unknown-linux-musl/release/examples/error-handling ./bootstra ``` 3. Upload to AWS Lambda ``` -aws lambda update-function-code --region us-east-1 --function-name ReturnValue --zip-file fileb://lambda.zip +aws lambda update-function-code --region us-east-1 --function-name RuntimeTest --zip-file fileb://lambda.zip ``` _Remember to replace the names and IDs with your own values._ From 64fcfc2223e1d9bf508d115ba9dd909dfaef757d Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 22 Jul 2020 10:46:32 +0000 Subject: [PATCH 04/19] Tidied up examples readme. --- lambda/examples/readme.md | 99 ++++++++++++++++++++++++++++++++++----- 1 file changed, 86 insertions(+), 13 deletions(-) diff --git a/lambda/examples/readme.md b/lambda/examples/readme.md index 4074f366..773a5f1c 100644 --- a/lambda/examples/readme.md +++ b/lambda/examples/readme.md @@ -1,25 +1,92 @@ ## How to compile and run the examples -1. Compile the example you want to run +1. Create a Lambda function called _RuntimeTest_ in AWS with a custom runtime and no code. + +2. Compile all examples ``` -cargo build --release --target x86_64-unknown-linux-musl --example error-handling +cargo build --release --target x86_64-unknown-linux-musl --examples ``` -2. Prepare the package +3. Prepare the package for the example you want to test, e.g. ``` -cp ./target/x86_64-unknown-linux-musl/release/examples/error-handling ./bootstrap && zip lambda.zip bootstrap && rm bootstrap +cp ./target/x86_64-unknown-linux-musl/release/examples/hello ./bootstrap && zip lambda.zip bootstrap && rm bootstrap +``` +4. Upload the package to AWS Lambda +``` +aws lambda update-function-code --region us-east-1 --function-name RuntimeTest --zip-file fileb://lambda.zip +``` +_Feel free to replace the names and IDs with your own values._ + +## basic.rs + +**Deployment**: +```bash +cp ./target/x86_64-unknown-linux-musl/release/examples/basic ./bootstrap && zip lambda.zip bootstrap && rm bootstrap +aws lambda update-function-code --region us-east-1 --function-name RuntimeTest --zip-file fileb://lambda.zip +``` + +**Test event JSON (success)**: +```json +{ "command": "do something" } ``` -3. Upload to AWS Lambda + +Sample response: +```json +{ + "msg": "Command do something executed.", + "req_id": "67a038e4-dc19-4adf-aa32-5ba09312c6ca" +} +``` + +**Test event JSON (error)**: +```json +{ "foo": "do something" } +``` + +Sample response: +```json +{ + "errorType": "alloc::boxed::Box", + "errorMessage": "missing field `command`" +} ``` + +## hello.rs + +The most basic example using `#[lambda]` macro to reduce the amount of boilerplate code. + +**Deployment**: +```bash +cp ./target/x86_64-unknown-linux-musl/release/examples/hello ./bootstrap && zip lambda.zip bootstrap && rm bootstrap aws lambda update-function-code --region us-east-1 --function-name RuntimeTest --zip-file fileb://lambda.zip ``` -_Remember to replace the names and IDs with your own values._ +**Test event JSON**: +```json +{ "foo": "bar" } +``` + +Sample response: +```json +{ + "foo": "bar" +} +``` + +## hello-without-macro.rs -## Error handling examples for aws-lambda-rust-runtime +The same as hello.rs example, but without `#[lambda]` macro to allow for more control at a lower level. -#### Error logging by the runtime +**Deployment**: +```bash +cp ./target/x86_64-unknown-linux-musl/release/examples/hello-without-macro ./bootstrap && zip lambda.zip bootstrap && rm bootstrap +aws lambda update-function-code --region us-east-1 --function-name RuntimeTest --zip-file fileb://lambda.zip +``` + +The test event JSON and the sample response are identical to that of _hello.rs_ example. + +## error-handling Errors are logged by the runtime only if `log` is initialised by the handler. These examples use `simple_logger`, but you can use any other provider that works with `log`. @@ -27,11 +94,17 @@ These examples use `simple_logger`, but you can use any other provider that work simple_logger::init_with_level(log::Level::Debug)?; ``` +**Deployment**: +```bash +cp ./target/x86_64-unknown-linux-musl/release/examples/error-handling ./bootstrap && zip lambda.zip bootstrap && rm bootstrap +aws lambda update-function-code --region us-east-1 --function-name RuntimeTest --zip-file fileb://lambda.zip +``` + #### Sample log output The following input/output examples correspond to different `match` arms in the handler of `error-handling.rs`. -### Invalid JSON input +### Invalid event JSON Test input: ```json @@ -58,7 +131,7 @@ REPORT RequestId: b98e07c6-e2ba-4ca6-9968-d0b94729ddba Duration: 2.06 ms Billed ### A simple text-only error -Test input: +Test event JSON: ```json { "event_type": "SimpleError" @@ -83,7 +156,7 @@ REPORT RequestId: 77c66dbf-bd60-4f77-8453-682d0bceba91 Duration: 0.98 ms Billed ### A custom error with JSON output for Display trait -Test input: +Test event JSON: ```json { "event_type": "CustomError" @@ -108,7 +181,7 @@ REPORT RequestId: b46b0588-1383-4224-bc7a-42b0d61930c1 Duration: 0.91 ms Billed ### A 3rd party error from _std::fs::File::open_ -Test input: +Test event JSON: ```json { "event_type": "ExternalError" @@ -133,7 +206,7 @@ REPORT RequestId: 893d24e5-cb79-4f6f-bae0-36304c62e9da Duration: 1.15 ms Billed ### A response to a successful Lambda execution -Test input: +Test event JSON: ```json { "event_type": "Response" From 96a90afb462e0a7fdcf570141b92b0b6d702db10 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 22 Jul 2020 10:51:16 +0000 Subject: [PATCH 05/19] Fixed headers in examples readme. --- lambda/examples/readme.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lambda/examples/readme.md b/lambda/examples/readme.md index 773a5f1c..fd69ba9d 100644 --- a/lambda/examples/readme.md +++ b/lambda/examples/readme.md @@ -100,11 +100,9 @@ cp ./target/x86_64-unknown-linux-musl/release/examples/error-handling ./bootstra aws lambda update-function-code --region us-east-1 --function-name RuntimeTest --zip-file fileb://lambda.zip ``` -#### Sample log output - The following input/output examples correspond to different `match` arms in the handler of `error-handling.rs`. -### Invalid event JSON +#### Invalid event JSON Test input: ```json @@ -129,7 +127,7 @@ END RequestId: b98e07c6-e2ba-4ca6-9968-d0b94729ddba REPORT RequestId: b98e07c6-e2ba-4ca6-9968-d0b94729ddba Duration: 2.06 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 28 MB Init Duration: 33.67 ms ``` -### A simple text-only error +#### A simple text-only error Test event JSON: ```json @@ -154,7 +152,7 @@ END RequestId: 77c66dbf-bd60-4f77-8453-682d0bceba91 REPORT RequestId: 77c66dbf-bd60-4f77-8453-682d0bceba91 Duration: 0.98 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 28 MB ``` -### A custom error with JSON output for Display trait +#### A custom error with JSON output for Display trait Test event JSON: ```json @@ -179,7 +177,7 @@ END RequestId: b46b0588-1383-4224-bc7a-42b0d61930c1 REPORT RequestId: b46b0588-1383-4224-bc7a-42b0d61930c1 Duration: 0.91 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 29 MB ``` -### A 3rd party error from _std::fs::File::open_ +#### A 3rd party error from _std::fs::File::open_ Test event JSON: ```json @@ -204,7 +202,7 @@ END RequestId: 893d24e5-cb79-4f6f-bae0-36304c62e9da REPORT RequestId: 893d24e5-cb79-4f6f-bae0-36304c62e9da Duration: 1.15 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 29 MB ``` -### A response to a successful Lambda execution +#### A response to a successful Lambda execution Test event JSON: ```json From 5d07f3f975fb8b4efe97de0b61f298652c7e0a0f Mon Sep 17 00:00:00 2001 From: rimutaka Date: Wed, 22 Jul 2020 11:11:25 +0000 Subject: [PATCH 06/19] Formatting fix in error-handling.rs. --- lambda/examples/error-handling.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lambda/examples/error-handling.rs b/lambda/examples/error-handling.rs index 2e2799ea..3107eab6 100644 --- a/lambda/examples/error-handling.rs +++ b/lambda/examples/error-handling.rs @@ -2,11 +2,10 @@ use lambda::handler_fn; use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; -use simple_logger; use simple_error; +use simple_logger; use std::fs::File; - /// A shorthand for `Box` type required by aws-lambda-rust-runtime. pub type Error = Box; @@ -54,9 +53,7 @@ pub(crate) async fn func(event: Value, ctx: lambda::Context) -> Result { // generate a simple text message error using `simple_error` crate - return Err(Box::new(simple_error::SimpleError::new( - "A simple error as requested!", - ))); + return Err(Box::new(simple_error::SimpleError::new("A simple error as requested!"))); } Ok(v) if v.event_type == EventType::CustomError => { // generate a custom error using our own structure From 82d235195d053601e9a9a9d26abeef66e4e37a47 Mon Sep 17 00:00:00 2001 From: rimutaka Date: Wed, 22 Jul 2020 11:22:10 +0000 Subject: [PATCH 07/19] Fixed comment in lib.rs --- lambda/src/lib.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lambda/src/lib.rs b/lambda/src/lib.rs index e3e8d102..6b315879 100644 --- a/lambda/src/lib.rs +++ b/lambda/src/lib.rs @@ -232,11 +232,8 @@ where Ok(()) } -/// Returns the name of as a slice, but it is always the same -/// value for all errors: -/// ``` -/// "alloc::boxed::Box" -/// ``` +/// Returns the name of as a slice, but the value is +/// the same for all errors because the type is the same. fn type_name_of_val(_: T) -> &'static str { std::any::type_name::() } From 5f63aa952a4e22b386f657620e06b7c7d410f5b3 Mon Sep 17 00:00:00 2001 From: mx Date: Thu, 23 Jul 2020 12:53:39 +1200 Subject: [PATCH 08/19] Corrected handler_fn interface misconception in basic.rs Co-authored-by: Veetaha --- lambda/examples/basic.rs | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/lambda/examples/basic.rs b/lambda/examples/basic.rs index e132b53f..616d0a52 100644 --- a/lambda/examples/basic.rs +++ b/lambda/examples/basic.rs @@ -18,14 +18,9 @@ async fn main() -> Result<(), Error> { Ok(()) } -pub(crate) async fn my_handler(event: Value, ctx: Context) -> Result { +pub(crate) async fn my_handler(event: Request, ctx: Context) -> Result { // extract some useful info from the request - let command = match serde_json::from_value::(event) { - Err(e) => { - return Err(Box::new(e)); - } - Ok(v) => v.command, - }; + let command = event.command; // prepare the response let resp = Response { @@ -33,13 +28,13 @@ pub(crate) async fn my_handler(event: Value, ctx: Context) -> Result Date: Thu, 23 Jul 2020 01:20:45 +0000 Subject: [PATCH 09/19] Upper-cased and edited examples/readme.md --- lambda/examples/{readme.md => README.md} | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) rename lambda/examples/{readme.md => README.md} (93%) diff --git a/lambda/examples/readme.md b/lambda/examples/README.md similarity index 93% rename from lambda/examples/readme.md rename to lambda/examples/README.md index fd69ba9d..7ecbbb50 100644 --- a/lambda/examples/readme.md +++ b/lambda/examples/README.md @@ -47,10 +47,11 @@ Sample response: Sample response: ```json { - "errorType": "alloc::boxed::Box", - "errorMessage": "missing field `command`" + "errorType": "Runtime.ExitError", + "errorMessage": "RequestId: 586366df-f271-4e6e-9c30-b3dcab30f4e8 Error: Runtime exited with error: exit status 1" } ``` +The runtime could not deserialize our invalid input, but it did not give a detailed explanation why the error occurred. See _error-handling.rs_ example for more error handling options. ## hello.rs @@ -86,9 +87,9 @@ aws lambda update-function-code --region us-east-1 --function-name RuntimeTest - The test event JSON and the sample response are identical to that of _hello.rs_ example. -## error-handling +## error-handling.rs -Errors are logged by the runtime only if `log` is initialised by the handler. +Errors are logged by the runtime only if `log` is initialized by the handler. These examples use `simple_logger`, but you can use any other provider that works with `log`. ``` simple_logger::init_with_level(log::Level::Debug)?; From ad25ed7154c9c98ddc4437a7a12415ace2ecc0bd Mon Sep 17 00:00:00 2001 From: rimutaka Date: Thu, 23 Jul 2020 23:47:12 +0000 Subject: [PATCH 10/19] Added error handling for #241, interim, broken. --- lambda/Cargo.toml | 2 + lambda/examples/README.md | 250 ++++++++++++++++++ lambda/examples/basic.rs | 50 ++++ lambda/examples/error-handling.rs | 107 ++++++++ lambda/examples/hello-without-macro-log.rs | 3 +- .../examples/hello-without-macro-tracing.rs | 3 +- lambda/src/lib.rs | 8 +- 7 files changed, 417 insertions(+), 6 deletions(-) create mode 100644 lambda/examples/README.md create mode 100644 lambda/examples/basic.rs create mode 100644 lambda/examples/error-handling.rs diff --git a/lambda/Cargo.toml b/lambda/Cargo.toml index 796efec8..f8322171 100644 --- a/lambda/Cargo.toml +++ b/lambda/Cargo.toml @@ -31,3 +31,5 @@ async-stream = "0.2" tracing-subscriber = "0.2" once_cell = "1.4.0" simple_logger = "1.6.0" +log = "0.4" +simple-error = "0.2" diff --git a/lambda/examples/README.md b/lambda/examples/README.md new file mode 100644 index 00000000..7faee362 --- /dev/null +++ b/lambda/examples/README.md @@ -0,0 +1,250 @@ + +## How to compile and run the examples + +1. Create a Lambda function called _RuntimeTest_ in AWS with a custom runtime and no code. + +2. Compile all examples + +``` +cargo build --release --target x86_64-unknown-linux-musl --examples +``` +3. Prepare the package for the example you want to test, e.g. +``` +cp ./target/x86_64-unknown-linux-musl/release/examples/hello ./bootstrap && zip lambda.zip bootstrap && rm bootstrap +``` +4. Upload the package to AWS Lambda +``` +aws lambda update-function-code --region us-east-1 --function-name RuntimeTest --zip-file fileb://lambda.zip +``` +_Feel free to replace the names and IDs with your own values._ + +## basic.rs + +**Deployment**: +```bash +cp ./target/x86_64-unknown-linux-musl/release/examples/basic ./bootstrap && zip lambda.zip bootstrap && rm bootstrap +aws lambda update-function-code --region us-east-1 --function-name RuntimeTest --zip-file fileb://lambda.zip +``` + +**Test event JSON (success)**: +```json +{ "command": "do something" } +``` + +Sample response: +```json +{ + "msg": "Command do something executed.", + "req_id": "67a038e4-dc19-4adf-aa32-5ba09312c6ca" +} +``` + +**Test event JSON (error)**: +```json +{ "foo": "do something" } +``` + +Sample response: +```json +{ + "errorType": "Runtime.ExitError", + "errorMessage": "RequestId: 586366df-f271-4e6e-9c30-b3dcab30f4e8 Error: Runtime exited with error: exit status 1" +} +``` +The runtime could not deserialize our invalid input, but it did not give a detailed explanation why the error occurred in the response. More details appear in the CloudWatch log: +``` +START RequestId: 6e667f61-c5d4-4b07-a60f-cd1ab339c35f Version: $LATEST +Error: Error("missing field `command`", line: 1, column: 22) +END RequestId: 6e667f61-c5d4-4b07-a60f-cd1ab339c35f +REPORT RequestId: 6e667f61-c5d4-4b07-a60f-cd1ab339c35f Duration: 36.34 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 10 MB +RequestId: 6e667f61-c5d4-4b07-a60f-cd1ab339c35f Error: Runtime exited with error: exit status 1 +Runtime.ExitError +``` + + See _error-handling.rs_ example for more error handling options. + +## hello.rs + +The most basic example using `#[lambda]` macro to reduce the amount of boilerplate code. + +**Deployment**: +```bash +cp ./target/x86_64-unknown-linux-musl/release/examples/hello ./bootstrap && zip lambda.zip bootstrap && rm bootstrap +aws lambda update-function-code --region us-east-1 --function-name RuntimeTest --zip-file fileb://lambda.zip +``` + +**Test event JSON**: +```json +{ "foo": "bar" } +``` + +Sample response: +```json +{ + "foo": "bar" +} +``` + +## hello-without-macro-tracing.rs + +The same as hello.rs example, but without `#[lambda]` macro to allow for more control at a lower level. + +**Deployment**: +```bash +cp ./target/x86_64-unknown-linux-musl/release/examples/hello-without-macro-tracing ./bootstrap && zip lambda.zip bootstrap && rm bootstrap +aws lambda update-function-code --region us-east-1 --function-name RuntimeTest --zip-file fileb://lambda.zip +``` + +## hello-without-macro-log.rs + +The same as hello.rs example, but without `#[lambda]` macro to allow for more control at a lower level. + +**Deployment**: +```bash +cp ./target/x86_64-unknown-linux-musl/release/examples/hello-without-macro-log ./bootstrap && zip lambda.zip bootstrap && rm bootstrap +aws lambda update-function-code --region us-east-1 --function-name RuntimeTest --zip-file fileb://lambda.zip +``` + + + +The test event JSON and the sample response are identical to that of _hello.rs_ example. + +## error-handling.rs + +Errors are logged by the runtime only if `log` is initialized by the handler. +These examples use `simple_logger`, but you can use any other provider that works with `log`. +``` +simple_logger::init_with_level(log::Level::Debug)?; +``` + +**Deployment**: +```bash +cp ./target/x86_64-unknown-linux-musl/release/examples/error-handling ./bootstrap && zip lambda.zip bootstrap && rm bootstrap +aws lambda update-function-code --region us-east-1 --function-name RuntimeTest --zip-file fileb://lambda.zip +``` + +The following input/output examples correspond to different `match` arms in the handler of `error-handling.rs`. + +#### Invalid event JSON + +Test input: +```json +{ + "event_type": "WrongType" +} +``` + +Lambda output: +``` +{ + "errorType": "alloc::boxed::Box", + "errorMessage": "unknown variant `WrongType`, expected one of `Response`, `ExternalError`, `SimpleError`, `CustomError`" +} +``` + +CloudWatch records: +``` +START RequestId: b98e07c6-e2ba-4ca6-9968-d0b94729ddba Version: $LATEST +2020-07-21 04:28:52,630 ERROR [lambda] unknown variant `WrongType`, expected one of `Response`, `ExternalError`, `SimpleError`, `CustomError` +END RequestId: b98e07c6-e2ba-4ca6-9968-d0b94729ddba +REPORT RequestId: b98e07c6-e2ba-4ca6-9968-d0b94729ddba Duration: 2.06 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 28 MB Init Duration: 33.67 ms +``` + +#### A simple text-only error + +Test event JSON: +```json +{ + "event_type": "SimpleError" +} +``` + +Lambda output: +``` +{ + "errorType": "alloc::boxed::Box", + "errorMessage": "A simple error as requested!" +} +``` + +CloudWatch records: +``` +START RequestId: 77c66dbf-bd60-4f77-8453-682d0bceba91 Version: $LATEST +2020-07-21 04:35:28,044 ERROR [lambda] A simple error as requested! +END RequestId: 77c66dbf-bd60-4f77-8453-682d0bceba91 +REPORT RequestId: 77c66dbf-bd60-4f77-8453-682d0bceba91 Duration: 0.98 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 28 MB +``` + +#### A custom error with JSON output for Display trait + +Test event JSON: +```json +{ + "event_type": "CustomError" +} +``` + +Lambda output: +``` +{ + "errorType": "alloc::boxed::Box", + "errorMessage": "{\"is_authenticated\":false,\"msg\":\"A custom error as requested!\",\"req_id\":\"b46b0588-1383-4224-bc7a-42b0d61930c1\"}" +} +``` + +CloudWatch records: +``` +START RequestId: b46b0588-1383-4224-bc7a-42b0d61930c1 Version: $LATEST +2020-07-21 04:39:00,133 ERROR [lambda] {"is_authenticated":false,"msg":"A custom error as requested!","req_id":"b46b0588-1383-4224-bc7a-42b0d61930c1"} +END RequestId: b46b0588-1383-4224-bc7a-42b0d61930c1 +REPORT RequestId: b46b0588-1383-4224-bc7a-42b0d61930c1 Duration: 0.91 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 29 MB +``` + +#### A 3rd party error from _std::fs::File::open_ + +Test event JSON: +```json +{ + "event_type": "ExternalError" +} +``` + +Lambda output: +``` +{ + "errorType": "alloc::boxed::Box", + "errorMessage": "No such file or directory (os error 2)" +} +``` + +CloudWatch records: +``` +START RequestId: 893d24e5-cb79-4f6f-bae0-36304c62e9da Version: $LATEST +2020-07-21 04:43:56,254 ERROR [lambda] No such file or directory (os error 2) +END RequestId: 893d24e5-cb79-4f6f-bae0-36304c62e9da +REPORT RequestId: 893d24e5-cb79-4f6f-bae0-36304c62e9da Duration: 1.15 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 29 MB +``` + +#### A response to a successful Lambda execution + +Test event JSON: +```json +{ + "event_type": "Response" +} +``` + +Lambda output: +``` +{ + "msg": "OK", + "req_id": "9752a3ad-6566-44e4-aafd-74db1fd4f361" +} +``` + +CloudWatch records: +``` +START RequestId: 9752a3ad-6566-44e4-aafd-74db1fd4f361 Version: $LATEST +END RequestId: 9752a3ad-6566-44e4-aafd-74db1fd4f361 +REPORT RequestId: 9752a3ad-6566-44e4-aafd-74db1fd4f361 Duration: 0.89 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 29 MB +``` \ No newline at end of file diff --git a/lambda/examples/basic.rs b/lambda/examples/basic.rs new file mode 100644 index 00000000..de61b6f9 --- /dev/null +++ b/lambda/examples/basic.rs @@ -0,0 +1,50 @@ +use lambda::{handler_fn, Context}; +use serde::{Deserialize, Serialize}; +use simple_logger; + +/// A shorthand for `Box` +/// type required by aws-lambda-rust-runtime. +pub type Error = Box; + +#[tokio::main] +async fn main() -> Result<(), Error> { + // required to enable CloudWatch error logging by the runtime + // can be replaced with any other method of initializing `log` + simple_logger::init_with_level(log::Level::Info)?; + + let func = handler_fn(my_handler); + lambda::run(func).await?; + Ok(()) +} + +pub(crate) async fn my_handler(event: Request, ctx: Context) -> Result { + // extract some useful info from the request + let command = event.command; + + // prepare the response + let resp = Response { + req_id: ctx.request_id, + msg: format!("Command {} executed.", command), + }; + + // return `Response` (it will be serialized to JSON automatically by the runtime) + Ok(resp) +} + +/// This is a made-up example of what a response structure may look like. +/// There is no restriction on what it can be. The runtime requires responses +/// to be serialized into json. The runtime pays no attention +/// to the contents of the response payload. +#[derive(Serialize)] +struct Response { + req_id: String, + msg: String, +} + +/// This is also a made-up example. Requests come into the runtime as unicode +/// strings in json format, which can map to any structure that implements `serde::Deserialize` +/// The runtime pays no attention to the contents of the request payload. +#[derive(Deserialize)] +struct Request { + command: String, +} diff --git a/lambda/examples/error-handling.rs b/lambda/examples/error-handling.rs new file mode 100644 index 00000000..3107eab6 --- /dev/null +++ b/lambda/examples/error-handling.rs @@ -0,0 +1,107 @@ +/// See https://github.com/awslabs/aws-lambda-rust-runtime for more info on Rust runtime for AWS Lambda +use lambda::handler_fn; +use serde::{Deserialize, Serialize}; +use serde_json::{json, Value}; +use simple_error; +use simple_logger; +use std::fs::File; + +/// A shorthand for `Box` type required by aws-lambda-rust-runtime. +pub type Error = Box; + +#[derive(Debug, Serialize)] +struct CustomError { + is_authenticated: bool, + req_id: String, + msg: String, +} + +impl std::error::Error for CustomError { + // this implementation required `Debug` and `Display` traits +} + +impl std::fmt::Display for CustomError { + /// Display the error struct as a JSON string + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let err_as_json = json!(self).to_string(); + write!(f, "{}", err_as_json) + } +} + +/// The entry point called by aws-lambda-rust-runtime client for every new Lambda request. +#[tokio::main] +async fn main() -> Result<(), Error> { + simple_logger::init_with_level(log::Level::Debug)?; // Note, this can only be called once! + + // call the actual handler of the request + let func = handler_fn(func); + lambda::run(func).await?; + Ok(()) +} + +/// The actual handler of the Lambda request. +pub(crate) async fn func(event: Value, ctx: lambda::Context) -> Result { + // convert the JSON request to a struct + let req = serde_json::from_value::(event); + + // check if the conversion succeeded and what action was requested + match req { + Err(e) => { + // conversion from JSON to `Request` struct failed + // return serde_json error + return Err(Box::new(e)); + } + Ok(v) if v.event_type == EventType::SimpleError => { + // generate a simple text message error using `simple_error` crate + return Err(Box::new(simple_error::SimpleError::new("A simple error as requested!"))); + } + Ok(v) if v.event_type == EventType::CustomError => { + // generate a custom error using our own structure + let cust_err = CustomError { + is_authenticated: ctx.identity.is_some(), + req_id: ctx.request_id, + msg: "A custom error as requested!".into(), + }; + return Err(Box::new(cust_err)); + } + Ok(v) if v.event_type == EventType::ExternalError => { + // try to open a non-existent file to get an error and propagate it with `?` + let _file = File::open("non-existent-file.txt")?; + + // it should never execute past the above line + panic!(); + } + Ok(_) => { + // generate and return an OK response in JSON format + let resp = Response { + req_id: ctx.request_id, + msg: "OK".into(), + }; + + return Ok(json!(resp)); + } + } +} + +/// A simple Lambda response structure. +#[derive(Serialize)] +struct Response { + req_id: String, + msg: String, +} + +/// A simple Lambda request structure with just one field +/// that tells the Lambda what is expected of it. +#[derive(Deserialize)] +struct Request { + event_type: EventType, +} + +/// Event types that tell our Lambda what to do do. +#[derive(Deserialize, PartialEq)] +enum EventType { + Response, + ExternalError, + SimpleError, + CustomError, +} diff --git a/lambda/examples/hello-without-macro-log.rs b/lambda/examples/hello-without-macro-log.rs index a2059b8c..80598c14 100644 --- a/lambda/examples/hello-without-macro-log.rs +++ b/lambda/examples/hello-without-macro-log.rs @@ -15,5 +15,6 @@ async fn main() -> Result<(), Error> { } async fn func(event: Value, _: Context) -> Result { - Ok(event) + //Ok(event) + Err(simple_error::SimpleError::new("simple error").into()) } diff --git a/lambda/examples/hello-without-macro-tracing.rs b/lambda/examples/hello-without-macro-tracing.rs index 8d46a853..580b7197 100644 --- a/lambda/examples/hello-without-macro-tracing.rs +++ b/lambda/examples/hello-without-macro-tracing.rs @@ -22,5 +22,6 @@ async fn main() -> Result<(), Error> { } async fn func(event: Value, _: Context) -> Result { - Ok(event) + //Ok(event) + Err(simple_error::SimpleError::new("simple error").into()) } diff --git a/lambda/src/lib.rs b/lambda/src/lib.rs index 0dadbf74..0a0c335a 100644 --- a/lambda/src/lib.rs +++ b/lambda/src/lib.rs @@ -131,7 +131,7 @@ impl Handler for HandlerFn where F: Fn(A, Context) -> Fut, Fut: Future> + Send + Sync, - Error: Into> + fmt::Debug, + Error: Into> + fmt::Display, { type Error = Error; type Fut = Fut; @@ -174,7 +174,7 @@ where where F: Handler + Send + Sync + 'static, >::Fut: Future>::Error>> + Send + Sync + 'static, - >::Error: fmt::Debug + Send + Sync + 'static, + >::Error: fmt::Display + Send + Sync + 'static, A: for<'de> Deserialize<'de> + Send + Sync + 'static, B: Serialize + Send + Sync + 'static, { @@ -204,7 +204,7 @@ where request_id, diagnostic: Diagnostic { error_type: type_name_of_val(&err).to_owned(), - error_message: format!("{:?}", err), + error_message: format!("{}", err), }, } .into_req(), @@ -317,7 +317,7 @@ pub async fn run(handler: F) -> Result<(), Error> where F: Handler + Send + Sync + 'static, >::Fut: Future>::Error>> + Send + Sync + 'static, - >::Error: fmt::Debug + Send + Sync + 'static, + >::Error: fmt::Display + Send + Sync + 'static, A: for<'de> Deserialize<'de> + Send + Sync + 'static, B: Serialize + Send + Sync + 'static, { From a9de2fcb24030a00e402348aba3c368b717feb6d Mon Sep 17 00:00:00 2001 From: Yogendra Sharma Date: Fri, 24 Jul 2020 21:59:13 +0530 Subject: [PATCH 11/19] #245 Fix for Invalid URL in README (#246) --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ae54457d..bd8a6d4a 100644 --- a/README.md +++ b/README.md @@ -190,7 +190,11 @@ pub trait Handler { `Handler` provides a default implementation that enables you to provide a Rust closure or function pointer to the `lambda!()` macro. -Optionally, you can pass your own instance of Tokio runtime to the `lambda!()` macro. See our [`with_custom_runtime.rs` example](https://github.com/awslabs/aws-lambda-rust-runtime/tree/master/lambda-runtime/examples/with_custom_runtime.rs) +Optionally, you can pass your own instance of Tokio runtime to the `lambda!()` macro: +``` +let rt = tokio::runtime::Runtime::new()?; +lambda!(my_handler, rt); +``` ## AWS event objects From 59227cd1bd0016c01319a0dac8ced8c665837711 Mon Sep 17 00:00:00 2001 From: rimutaka Date: Sat, 25 Jul 2020 09:49:26 +0000 Subject: [PATCH 12/19] Added err logging to lib.rs, consolidated examples --- lambda/examples/README.md | 28 ++--------------- lambda/examples/basic.rs | 3 ++ lambda/examples/error-handling.rs | 22 ++++++++++---- lambda/examples/hello-without-macro-log.rs | 20 ------------- .../examples/hello-without-macro-tracing.rs | 27 ----------------- lambda/examples/{hello.rs => macro.rs} | 0 lambda/src/lib.rs | 30 +++++++++++-------- 7 files changed, 40 insertions(+), 90 deletions(-) delete mode 100644 lambda/examples/hello-without-macro-log.rs delete mode 100644 lambda/examples/hello-without-macro-tracing.rs rename lambda/examples/{hello.rs => macro.rs} (100%) diff --git a/lambda/examples/README.md b/lambda/examples/README.md index 7faee362..7f10f139 100644 --- a/lambda/examples/README.md +++ b/lambda/examples/README.md @@ -63,13 +63,13 @@ Runtime.ExitError See _error-handling.rs_ example for more error handling options. -## hello.rs +## macro.rs The most basic example using `#[lambda]` macro to reduce the amount of boilerplate code. **Deployment**: ```bash -cp ./target/x86_64-unknown-linux-musl/release/examples/hello ./bootstrap && zip lambda.zip bootstrap && rm bootstrap +cp ./target/x86_64-unknown-linux-musl/release/examples/macro ./bootstrap && zip lambda.zip bootstrap && rm bootstrap aws lambda update-function-code --region us-east-1 --function-name RuntimeTest --zip-file fileb://lambda.zip ``` @@ -85,30 +85,6 @@ Sample response: } ``` -## hello-without-macro-tracing.rs - -The same as hello.rs example, but without `#[lambda]` macro to allow for more control at a lower level. - -**Deployment**: -```bash -cp ./target/x86_64-unknown-linux-musl/release/examples/hello-without-macro-tracing ./bootstrap && zip lambda.zip bootstrap && rm bootstrap -aws lambda update-function-code --region us-east-1 --function-name RuntimeTest --zip-file fileb://lambda.zip -``` - -## hello-without-macro-log.rs - -The same as hello.rs example, but without `#[lambda]` macro to allow for more control at a lower level. - -**Deployment**: -```bash -cp ./target/x86_64-unknown-linux-musl/release/examples/hello-without-macro-log ./bootstrap && zip lambda.zip bootstrap && rm bootstrap -aws lambda update-function-code --region us-east-1 --function-name RuntimeTest --zip-file fileb://lambda.zip -``` - - - -The test event JSON and the sample response are identical to that of _hello.rs_ example. - ## error-handling.rs Errors are logged by the runtime only if `log` is initialized by the handler. diff --git a/lambda/examples/basic.rs b/lambda/examples/basic.rs index de61b6f9..77318999 100644 --- a/lambda/examples/basic.rs +++ b/lambda/examples/basic.rs @@ -1,3 +1,6 @@ +// This example requires the following input to succeed: +// { "command": "do something" } + use lambda::{handler_fn, Context}; use serde::{Deserialize, Serialize}; use simple_logger; diff --git a/lambda/examples/error-handling.rs b/lambda/examples/error-handling.rs index 3107eab6..08f43f75 100644 --- a/lambda/examples/error-handling.rs +++ b/lambda/examples/error-handling.rs @@ -2,8 +2,6 @@ use lambda::handler_fn; use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; -use simple_error; -use simple_logger; use std::fs::File; /// A shorthand for `Box` type required by aws-lambda-rust-runtime. @@ -28,10 +26,24 @@ impl std::fmt::Display for CustomError { } } -/// The entry point called by aws-lambda-rust-runtime client for every new Lambda request. #[tokio::main] async fn main() -> Result<(), Error> { - simple_logger::init_with_level(log::Level::Debug)?; // Note, this can only be called once! + // The runtime logging can be enabled here by initializing `log` with `simple_logger` + // or another compatible crate. The runtime is using `tracing` internally. + // You can comment out the `simple_logger` init line and uncomment the following block to + // use `tracing` in the handler function. + // + simple_logger::init_with_level(log::Level::Info)?; + /* + tracing_subscriber::fmt() + .with_max_level(tracing::Level::INFO) + // this needs to be set to false, otherwise ANSI color codes will + // show up in a confusing manner in CloudWatch logs. + .with_ansi(false) + // disabling time is handy because CloudWatch will add the ingestion time. + .without_time() + .init(); + */ // call the actual handler of the request let func = handler_fn(func); @@ -69,7 +81,7 @@ pub(crate) async fn func(event: Value, ctx: lambda::Context) -> Result { // generate and return an OK response in JSON format diff --git a/lambda/examples/hello-without-macro-log.rs b/lambda/examples/hello-without-macro-log.rs deleted file mode 100644 index 80598c14..00000000 --- a/lambda/examples/hello-without-macro-log.rs +++ /dev/null @@ -1,20 +0,0 @@ -use lambda::{handler_fn, Context}; -use serde_json::Value; -use tracing::info; - -type Error = Box; - -#[tokio::main] -async fn main() -> Result<(), Error> { - let func = handler_fn(func); - simple_logger::init().unwrap(); - - info!("Hello!"); - lambda::run(func).await?; - Ok(()) -} - -async fn func(event: Value, _: Context) -> Result { - //Ok(event) - Err(simple_error::SimpleError::new("simple error").into()) -} diff --git a/lambda/examples/hello-without-macro-tracing.rs b/lambda/examples/hello-without-macro-tracing.rs deleted file mode 100644 index 580b7197..00000000 --- a/lambda/examples/hello-without-macro-tracing.rs +++ /dev/null @@ -1,27 +0,0 @@ -use lambda::{handler_fn, Context}; -use serde_json::Value; -use tracing::info; - -type Error = Box; - -#[tokio::main] -async fn main() -> Result<(), Error> { - let func = handler_fn(func); - tracing_subscriber::fmt() - .with_max_level(tracing::Level::TRACE) - // this needs to be set to false, otherwise ANSI color codes will - // show up in a confusing manner in CloudWatch logs. - .with_ansi(false) - // disabling time is handy because CloudWatch will add the ingestion time. - .without_time() - .init(); - - info!("Hello!"); - lambda::run(func).await?; - Ok(()) -} - -async fn func(event: Value, _: Context) -> Result { - //Ok(event) - Err(simple_error::SimpleError::new("simple error").into()) -} diff --git a/lambda/examples/hello.rs b/lambda/examples/macro.rs similarity index 100% rename from lambda/examples/hello.rs rename to lambda/examples/macro.rs diff --git a/lambda/src/lib.rs b/lambda/src/lib.rs index 0a0c335a..a4bebe2b 100644 --- a/lambda/src/lib.rs +++ b/lambda/src/lib.rs @@ -55,7 +55,7 @@ use tokio::{ stream::{Stream, StreamExt}, }; use tower_service::Service; -use tracing::trace; +use tracing::{error, trace}; mod client; mod requests; @@ -200,23 +200,29 @@ where body: response, } .into_req(), - Err(err) => EventErrorRequest { + Err(err) => { + error!("{}", err); // logs the error in CloudWatch + EventErrorRequest { + request_id, + diagnostic: Diagnostic { + error_type: type_name_of_val(&err).to_owned(), + error_message: format!("{}", err), // returns the error to the caller via Lambda API + }, + } + .into_req() + } + }, + Err(err) if err.is_panic() => { + error!("Lambda panicked!"); + EventErrorRequest { request_id, diagnostic: Diagnostic { error_type: type_name_of_val(&err).to_owned(), - error_message: format!("{}", err), + error_message: "Lambda panicked!".to_owned(), }, } - .into_req(), - }, - Err(err) if err.is_panic() => EventErrorRequest { - request_id, - diagnostic: Diagnostic { - error_type: type_name_of_val(&err).to_owned(), - error_message: "Lambda panicked!".to_owned(), - }, + .into_req() } - .into_req(), Err(_) => unreachable!("tokio::task should not be canceled"), }; let req = req?; From e40ea17b8627b84ae3503873ff34024cde0283f7 Mon Sep 17 00:00:00 2001 From: rimutaka Date: Sat, 25 Jul 2020 23:40:45 +0000 Subject: [PATCH 13/19] Log panic as Debug+Display, improved examples --- lambda/examples/README.md | 28 +++++++++++++ lambda/examples/basic.rs | 36 ++++++++-------- lambda/examples/error-handling.rs | 70 +++++++++++++++---------------- lambda/src/lib.rs | 4 +- 4 files changed, 81 insertions(+), 57 deletions(-) diff --git a/lambda/examples/README.md b/lambda/examples/README.md index 7f10f139..51a5a10b 100644 --- a/lambda/examples/README.md +++ b/lambda/examples/README.md @@ -201,6 +201,34 @@ END RequestId: 893d24e5-cb79-4f6f-bae0-36304c62e9da REPORT RequestId: 893d24e5-cb79-4f6f-bae0-36304c62e9da Duration: 1.15 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 29 MB ``` +#### Handler panic + +Test event JSON: +```json +{ + "event_type": "Panic" +} +``` + +Lambda output: +``` +{ + "errorType": "Runtime.ExitError", + "errorMessage": "RequestId: 2d579019-07f7-409a-a6e6-af7725253307 Error: Runtime exited with error: exit status 101" +} +``` + +CloudWatch records: +``` +START RequestId: 2d579019-07f7-409a-a6e6-af7725253307 Version: $LATEST +thread 'main' panicked at 'explicit panic', lambda/examples/error-handling.rs:87:13 +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace +END RequestId: 2d579019-07f7-409a-a6e6-af7725253307 +REPORT RequestId: 2d579019-07f7-409a-a6e6-af7725253307 Duration: 43.40 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 27 MB Init Duration: 23.15 ms +RequestId: 2d579019-07f7-409a-a6e6-af7725253307 Error: Runtime exited with error: exit status 101 +Runtime.ExitError +``` + #### A response to a successful Lambda execution Test event JSON: diff --git a/lambda/examples/basic.rs b/lambda/examples/basic.rs index 77318999..2d2ad02d 100644 --- a/lambda/examples/basic.rs +++ b/lambda/examples/basic.rs @@ -9,6 +9,24 @@ use simple_logger; /// type required by aws-lambda-rust-runtime. pub type Error = Box; +/// This is also a made-up example. Requests come into the runtime as unicode +/// strings in json format, which can map to any structure that implements `serde::Deserialize` +/// The runtime pays no attention to the contents of the request payload. +#[derive(Deserialize)] +struct Request { + command: String, +} + +/// This is a made-up example of what a response structure may look like. +/// There is no restriction on what it can be. The runtime requires responses +/// to be serialized into json. The runtime pays no attention +/// to the contents of the response payload. +#[derive(Serialize)] +struct Response { + req_id: String, + msg: String, +} + #[tokio::main] async fn main() -> Result<(), Error> { // required to enable CloudWatch error logging by the runtime @@ -33,21 +51,3 @@ pub(crate) async fn my_handler(event: Request, ctx: Context) -> Result` type required by aws-lambda-rust-runtime. pub type Error = Box; +/// A simple Lambda request structure with just one field +/// that tells the Lambda what is expected of it. +#[derive(Deserialize)] +struct Request { + event_type: EventType, +} + +/// Event types that tell our Lambda what to do do. +#[derive(Deserialize, PartialEq)] +enum EventType { + Response, + ExternalError, + SimpleError, + CustomError, + Panic, +} + +/// A simple Lambda response structure. +#[derive(Serialize)] +struct Response { + req_id: String, + msg: String, +} + #[derive(Debug, Serialize)] struct CustomError { is_authenticated: bool, @@ -53,21 +77,13 @@ async fn main() -> Result<(), Error> { /// The actual handler of the Lambda request. pub(crate) async fn func(event: Value, ctx: lambda::Context) -> Result { - // convert the JSON request to a struct - let req = serde_json::from_value::(event); - - // check if the conversion succeeded and what action was requested - match req { - Err(e) => { - // conversion from JSON to `Request` struct failed - // return serde_json error - return Err(Box::new(e)); - } - Ok(v) if v.event_type == EventType::SimpleError => { + // check what action was requested + match serde_json::from_value::(event)?.event_type { + EventType::SimpleError => { // generate a simple text message error using `simple_error` crate return Err(Box::new(simple_error::SimpleError::new("A simple error as requested!"))); } - Ok(v) if v.event_type == EventType::CustomError => { + EventType::CustomError => { // generate a custom error using our own structure let cust_err = CustomError { is_authenticated: ctx.identity.is_some(), @@ -76,14 +92,17 @@ pub(crate) async fn func(event: Value, ctx: lambda::Context) -> Result { + EventType::ExternalError => { // try to open a non-existent file to get an error and propagate it with `?` let _file = File::open("non-existent-file.txt")?; // it should never execute past the above line unreachable!(); } - Ok(_) => { + EventType::Panic => { + panic!(); + } + EventType::Response => { // generate and return an OK response in JSON format let resp = Response { req_id: ctx.request_id, @@ -94,26 +113,3 @@ pub(crate) async fn func(event: Value, ctx: lambda::Context) -> Result { - error!("Lambda panicked!"); + error!("{:?}", err); // inconsistent with other log record formats - to be reviewed EventErrorRequest { request_id, diagnostic: Diagnostic { error_type: type_name_of_val(&err).to_owned(), - error_message: "Lambda panicked!".to_owned(), + error_message: format!("Lambda panicked: {}", err), }, } .into_req() From e2ae1e56edc3c187198da39d46d20c4ff1db5adb Mon Sep 17 00:00:00 2001 From: rimutaka Date: Sat, 25 Jul 2020 23:47:35 +0000 Subject: [PATCH 14/19] client.rs formatting fix --- lambda/src/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambda/src/client.rs b/lambda/src/client.rs index 88de0037..82b6e64c 100644 --- a/lambda/src/client.rs +++ b/lambda/src/client.rs @@ -63,10 +63,10 @@ mod endpoint_tests { use hyper::{server::conn::Http, service::service_fn, Body}; use serde_json::json; use std::convert::TryFrom; - use tokio::stream::StreamExt; use tokio::{ io::{AsyncRead, AsyncWrite}, select, + stream::StreamExt, sync::{self, oneshot}, }; From 7e58282e643610765b98d250c4b7d5818a5b33e5 Mon Sep 17 00:00:00 2001 From: rimutaka Date: Sun, 26 Jul 2020 10:15:06 +0000 Subject: [PATCH 15/19] Fixed "Process exited" error in lib.rs. --- lambda/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambda/src/lib.rs b/lambda/src/lib.rs index 25997fbd..15b347e7 100644 --- a/lambda/src/lib.rs +++ b/lambda/src/lib.rs @@ -337,7 +337,7 @@ where .expect("Unable create runtime"); let client = &runtime.client; - let incoming = incoming(client).take(1); + let incoming = incoming(client); runtime.run(incoming, handler).await } From 7d9955550d836465c42d9a7a08d74d49b720dd03 Mon Sep 17 00:00:00 2001 From: rimutaka Date: Sun, 26 Jul 2020 11:01:49 +0000 Subject: [PATCH 16/19] Added some tracing!() to lib.rs. --- lambda/src/lib.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lambda/src/lib.rs b/lambda/src/lib.rs index 15b347e7..fb53aa8e 100644 --- a/lambda/src/lib.rs +++ b/lambda/src/lib.rs @@ -182,11 +182,13 @@ where let handler = Arc::new(handler); tokio::pin!(incoming); while let Some(event) = incoming.next().await { + trace!("New event arrived (run loop)"); let event = event?; let (parts, body) = event.into_parts(); let ctx: Context = Context::try_from(parts.headers)?; let body = hyper::body::to_bytes(body).await?; + trace!("{}", std::str::from_utf8(&body)?); // this may be very verbose let body = serde_json::from_slice(&body)?; let handler = Arc::clone(&handler); @@ -195,11 +197,14 @@ where let req = match task.await { Ok(response) => match response.await { - Ok(response) => EventCompletionRequest { - request_id, - body: response, + Ok(response) => { + trace!("Ok response from handler (run loop)"); + EventCompletionRequest { + request_id, + body: response, + } + .into_req() } - .into_req(), Err(err) => { error!("{}", err); // logs the error in CloudWatch EventErrorRequest { @@ -291,6 +296,7 @@ where { async_stream::stream! { loop { + trace!("Waiting for next event (incoming loop)"); let req = NextEventRequest.into_req().expect("Unable to construct request"); let res = client.call(req).await; yield res; From 166d63848419639c5c30ad3c263781613f8f9341 Mon Sep 17 00:00:00 2001 From: rimutaka Date: Mon, 17 Aug 2020 23:28:05 +0000 Subject: [PATCH 17/19] Enforced Send+Sync for http Handler impl. --- lambda-http/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lambda-http/src/lib.rs b/lambda-http/src/lib.rs index cf7e3eff..5d6fb32e 100644 --- a/lambda-http/src/lib.rs +++ b/lambda-http/src/lib.rs @@ -122,7 +122,7 @@ pub trait Handler: Sized { /// The type of Response this Handler will return type Response: IntoResponse; /// The type of Future this Handler will return - type Fut: Future> + 'static; + type Fut: Future> + Send + Sync + 'static; /// Function used to execute handler behavior fn call(&self, event: Request, context: Context) -> Self::Fut; } @@ -137,7 +137,7 @@ impl Handler for F where F: Fn(Request, Context) -> Fut, R: IntoResponse, - Fut: Future> + Send + 'static, + Fut: Future> + Send + Sync + 'static, { type Response = R; type Error = Error; @@ -150,7 +150,7 @@ where #[doc(hidden)] pub struct TransformResponse { is_alb: bool, - fut: Pin>>>, + fut: Pin> + Send + Sync>>, } impl Future for TransformResponse From 186b4dbec07bc8b3325d653491d596c5099a7e59 Mon Sep 17 00:00:00 2001 From: rimutaka Date: Tue, 18 Aug 2020 00:39:15 +0000 Subject: [PATCH 18/19] Added docs and missing _vars to reduce warnings --- lambda-http/src/request.rs | 56 +++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/lambda-http/src/request.rs b/lambda-http/src/request.rs index fd4e52d9..287a789a 100644 --- a/lambda-http/src/request.rs +++ b/lambda-http/src/request.rs @@ -102,42 +102,65 @@ impl LambdaRequest<'_> { } } +/// See [context-variable-reference](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html) for more detail. #[derive(Deserialize, Debug, Clone)] #[serde(rename_all = "camelCase")] pub struct ApiGatewayV2RequestContext { + /// The API owner's AWS account ID. pub account_id: String, + /// The identifier API Gateway assigns to your API. pub api_id: String, + /// The stringified value of the specified key-value pair of the context map returned from an API Gateway Lambda authorizer function. #[serde(default)] pub authorizer: HashMap, + /// The full domain name used to invoke the API. This should be the same as the incoming Host header. pub domain_name: String, + /// The first label of the $context.domainName. This is often used as a caller/customer identifier. pub domain_prefix: String, + /// The HTTP method used. pub http: Http, + /// The ID that API Gateway assigns to the API request. pub request_id: String, + /// Undocumented, could be resourcePath pub route_key: String, + /// The deployment stage of the API request (for example, Beta or Prod). pub stage: String, + /// Undocumented, could be requestTime pub time: String, + /// Undocumented, could be requestTimeEpoch pub time_epoch: usize, } +/// See [context-variable-reference](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html) for more detail. #[derive(Deserialize, Debug, Clone)] #[serde(rename_all = "camelCase")] pub struct ApiGatewayRequestContext { - //pub path: String, + /// The API owner's AWS account ID. pub account_id: String, + /// The identifier that API Gateway assigns to your resource. pub resource_id: String, + /// The deployment stage of the API request (for example, Beta or Prod). pub stage: String, + /// The ID that API Gateway assigns to the API request. pub request_id: String, + /// The path to your resource. For example, for the non-proxy request URI of `https://{rest-api-id.execute-api.{region}.amazonaws.com/{stage}/root/child`, The $context.resourcePath value is /root/child. pub resource_path: String, + /// The HTTP method used. Valid values include: DELETE, GET, HEAD, OPTIONS, PATCH, POST, and PUT. pub http_method: String, + /// The stringified value of the specified key-value pair of the context map returned from an API Gateway Lambda authorizer function. #[serde(default)] pub authorizer: HashMap, + /// The identifier API Gateway assigns to your API. pub api_id: String, + /// Cofnito identity information pub identity: Identity, } +/// Elastic load balancer context information #[derive(Deserialize, Debug, Clone)] #[serde(rename_all = "camelCase")] pub struct AlbRequestContext { + /// Elastic load balancer context information pub elb: Elb, } @@ -167,10 +190,17 @@ pub struct Elb { #[serde(rename_all = "camelCase")] pub struct Http { #[serde(deserialize_with = "deserialize_method")] + /// The HTTP method used. Valid values include: DELETE, GET, HEAD, OPTIONS, PATCH, POST, and PUT. pub method: http::Method, + /// The request path. For example, for a non-proxy request URL of + /// `https://{rest-api-id.execute-api.{region}.amazonaws.com/{stage}/root/child`, + /// the $context.path value is `/{stage}/root/child`. pub path: String, + /// The request protocol, for example, HTTP/1.1. pub protocol: String, + /// The source IP address of the TCP connection making the request to API Gateway. pub source_ip: String, + /// The User-Agent header of the API caller. pub user_agent: String, } @@ -178,17 +208,35 @@ pub struct Http { #[derive(Deserialize, Debug, Default, Clone)] #[serde(rename_all = "camelCase")] pub struct Identity { + /// The source IP address of the TCP connection making the request to API Gateway. pub source_ip: String, + /// The Amazon Cognito identity ID of the caller making the request. + /// Available only if the request was signed with Amazon Cognito credentials. pub cognito_identity_id: Option, + /// The Amazon Cognito identity pool ID of the caller making the request. + /// Available only if the request was signed with Amazon Cognito credentials. pub cognito_identity_pool_id: Option, + /// A comma-separated list of the Amazon Cognito authentication providers used by the caller making the request. + /// Available only if the request was signed with Amazon Cognito credentials. pub cognito_authentication_provider: Option, + /// The Amazon Cognito authentication type of the caller making the request. + /// Available only if the request was signed with Amazon Cognito credentials. pub cognito_authentication_type: Option, + /// The AWS account ID associated with the request. pub account_id: Option, + /// The principal identifier of the caller making the request. pub caller: Option, + /// For API methods that require an API key, this variable is the API key associated with the method request. + /// For methods that don't require an API key, this variable is null. pub api_key: Option, + /// Undocumented. Can be the API key ID associated with an API request that requires an API key. + /// The description of `api_key` and `access_key` may actually be reversed. pub access_key: Option, + /// The principal identifier of the user making the request. Used in Lambda authorizers. pub user: Option, + /// The User-Agent header of the API caller. pub user_agent: Option, + /// The Amazon Resource Name (ARN) of the effective user identified after authentication. pub user_arn: Option, } @@ -352,7 +400,7 @@ impl<'a> From> for http::Request { .expect("failed to build request"); // no builder method that sets headers in batch - mem::replace(req.headers_mut(), headers); + let _ = mem::replace(req.headers_mut(), headers); req } @@ -416,7 +464,7 @@ impl<'a> From> for http::Request { } // no builder method that sets headers in batch - mem::replace(req.headers_mut(), multi_value_headers); + let _ = mem::replace(req.headers_mut(), multi_value_headers); req } @@ -477,7 +525,7 @@ impl<'a> From> for http::Request { } // no builder method that sets headers in batch - mem::replace(req.headers_mut(), multi_value_headers); + let _ = mem::replace(req.headers_mut(), multi_value_headers); req } From 8e845856eb5ce91a8b2369e5d8ae4a3525962af3 Mon Sep 17 00:00:00 2001 From: rimutaka Date: Wed, 19 Aug 2020 09:22:27 +0000 Subject: [PATCH 19/19] Removed unnecessary + Sync on handler's future --- lambda/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lambda/src/lib.rs b/lambda/src/lib.rs index fb53aa8e..9025717f 100644 --- a/lambda/src/lib.rs +++ b/lambda/src/lib.rs @@ -130,7 +130,7 @@ pub struct HandlerFn { impl Handler for HandlerFn where F: Fn(A, Context) -> Fut, - Fut: Future> + Send + Sync, + Fut: Future> + Send, Error: Into> + fmt::Display, { type Error = Error; @@ -173,7 +173,7 @@ where ) -> Result<(), Error> where F: Handler + Send + Sync + 'static, - >::Fut: Future>::Error>> + Send + Sync + 'static, + >::Fut: Future>::Error>> + Send + 'static, >::Error: fmt::Display + Send + Sync + 'static, A: for<'de> Deserialize<'de> + Send + Sync + 'static, B: Serialize + Send + Sync + 'static, @@ -328,7 +328,7 @@ where pub async fn run(handler: F) -> Result<(), Error> where F: Handler + Send + Sync + 'static, - >::Fut: Future>::Error>> + Send + Sync + 'static, + >::Fut: Future>::Error>> + Send + 'static, >::Error: fmt::Display + Send + Sync + 'static, A: for<'de> Deserialize<'de> + Send + Sync + 'static, B: Serialize + Send + Sync + 'static,