diff --git a/services/search-index-lambda/Cargo.lock b/services/search-index-lambda/Cargo.lock --- a/services/search-index-lambda/Cargo.lock +++ b/services/search-index-lambda/Cargo.lock @@ -41,12 +41,6 @@ "libc", ] -[[package]] -name = "anyhow" -version = "1.0.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" - [[package]] name = "async-stream" version = "0.3.5" @@ -66,7 +60,7 @@ dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.39", ] [[package]] @@ -217,6 +211,12 @@ "windows-targets", ] +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + [[package]] name = "core-foundation" version = "0.9.3" @@ -263,7 +263,7 @@ "proc-macro2", "quote", "strsim", - "syn", + "syn 2.0.39", ] [[package]] @@ -274,7 +274,7 @@ dependencies = [ "darling_core", "quote", - "syn", + "syn 2.0.39", ] [[package]] @@ -287,6 +287,19 @@ "serde", ] +[[package]] +name = "derive_more" +version = "0.99.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn 1.0.109", +] + [[package]] name = "either" version = "1.9.0" @@ -420,7 +433,7 @@ dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.39", ] [[package]] @@ -861,7 +874,7 @@ dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.39", ] [[package]] @@ -927,7 +940,7 @@ dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.39", ] [[package]] @@ -1080,6 +1093,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + [[package]] name = "rustix" version = "0.38.25" @@ -1112,9 +1134,9 @@ name = "search-index-lambda" version = "0.1.0" dependencies = [ - "anyhow", "aws-smithy-types", "aws_lambda_events", + "derive_more", "lambda_runtime", "openssl", "reqwest", @@ -1149,6 +1171,12 @@ "libc", ] +[[package]] +name = "semver" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" + [[package]] name = "serde" version = "1.0.193" @@ -1166,7 +1194,7 @@ dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.39", ] [[package]] @@ -1238,7 +1266,7 @@ "darling", "proc-macro2", "quote", - "syn", + "syn 2.0.39", ] [[package]] @@ -1291,6 +1319,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.39" @@ -1415,7 +1454,7 @@ dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.39", ] [[package]] @@ -1500,7 +1539,7 @@ dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.39", ] [[package]] @@ -1634,7 +1673,7 @@ "once_cell", "proc-macro2", "quote", - "syn", + "syn 2.0.39", "wasm-bindgen-shared", ] @@ -1668,7 +1707,7 @@ dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.39", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/services/search-index-lambda/Cargo.toml b/services/search-index-lambda/Cargo.toml --- a/services/search-index-lambda/Cargo.toml +++ b/services/search-index-lambda/Cargo.toml @@ -16,4 +16,4 @@ serde_derive = "1.0.193" serde = "1.0.193" aws-smithy-types = "1.1.1" -anyhow = "1.0.75" +derive_more = "0.99.17" diff --git a/services/search-index-lambda/src/error.rs b/services/search-index-lambda/src/error.rs new file mode 100644 --- /dev/null +++ b/services/search-index-lambda/src/error.rs @@ -0,0 +1,28 @@ +#[derive( + Debug, derive_more::Display, derive_more::From, derive_more::Error, +)] +pub enum Error { + #[display(fmt = "Payload Error: {:?}", _0)] + PayloadError(RecordError), + #[display(fmt = "Missing OPENSEARCH_ENDPOINT: {:?}", _0)] + MissingOpenSearchEndpoint(std::env::VarError), + #[display(fmt = "Serialization Error: {:?}", _0)] + SerializationError(serde_json::Error), + #[display(fmt = "Tracing Error {:?}", _0)] + TracingError(tracing::subscriber::SetGlobalDefaultError), + #[display(fmt = "Reqwest Error {:?}", _0)] + ReqwestError(reqwest::Error), + #[display(fmt = "Update Index Error: Status Code: {:?}", _0)] + UpdateIndexError(#[error(ignore)] reqwest::StatusCode), +} + +#[derive(Debug, derive_more::Display, derive_more::Error)] +pub enum RecordError { + InvalidAttributeType, + MissingEventName, + MissingDynamoDBStreamRecord, + MissingNewImage, + MissingOldImage, + MissingUserId, + MissingUsername, +} diff --git a/services/search-index-lambda/src/main.rs b/services/search-index-lambda/src/main.rs --- a/services/search-index-lambda/src/main.rs +++ b/services/search-index-lambda/src/main.rs @@ -1,109 +1,27 @@ -use anyhow::{anyhow, Result}; -use lambda_runtime::{service_fn, Error, LambdaEvent}; +use lambda_runtime::{service_fn, LambdaEvent}; use reqwest::Response; -use serde::{Deserialize, Serialize}; -use std::collections::HashMap; +use serde_derive::Serialize; use tracing::{self, Level}; use tracing_subscriber::EnvFilter; mod constants; +mod error; +mod payload; +mod query; -#[derive(Deserialize, Serialize, Debug)] -struct User { - #[serde(rename = "userID")] - user_id: String, - username: String, -} - -#[derive(Serialize, Deserialize)] -struct UpdateByQuery { - query: Query, - - #[serde(skip_serializing_if = "Option::is_none")] - script: Option