From 6f98452701e05780191c7bc77463edd79d319edc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Greinhofer?= Date: Fri, 6 Dec 2024 17:41:08 -0600 Subject: [PATCH] Fix Fargate run lambda MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes the missing argument required in the REST API call to create a new BNA pipeline. Drive-by: - Updates the bna-client version. Signed-off-by: Rémy Greinhofer --- Cargo.lock | 57 +++++++++++++++++++-------------- Cargo.toml | 15 ++++----- lambdas/Cargo.toml | 2 +- lambdas/src/bna-fargate-run.rs | 35 ++------------------ lambdas/src/bna-save-results.rs | 52 ++++++++++++++++++++++++++++-- lambdas/src/bna-teardown.rs | 5 +-- lambdas/src/lib.rs | 10 +++--- 7 files changed, 99 insertions(+), 77 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a7f5c5a..6bfe51b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -201,7 +201,7 @@ dependencies = [ "aws-sdk-sts", "aws-smithy-async", "aws-smithy-http", - "aws-smithy-json", + "aws-smithy-json 0.60.7", "aws-smithy-runtime", "aws-smithy-runtime-api", "aws-smithy-types", @@ -232,9 +232,9 @@ dependencies = [ [[package]] name = "aws-runtime" -version = "1.4.3" +version = "1.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a10d5c055aa540164d9561a0e2e74ad30f0dcf7393c3a92f6733ddf9c5762468" +checksum = "b5ac934720fbb46206292d2c75b57e67acfc56fe7dfd34fb9a02334af08409ea" dependencies = [ "aws-credential-types", "aws-sigv4", @@ -258,15 +258,15 @@ dependencies = [ [[package]] name = "aws-sdk-ecs" -version = "1.56.1" +version = "1.57.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e16010df1e43570f3a68ff18403feeeea40841693449ddfc5da1deff134227bc" +checksum = "d93300021f5086c929817c9deadedc2d4ce07ac498c78e55eeeeb8e5b691a797" dependencies = [ "aws-credential-types", "aws-runtime", "aws-smithy-async", "aws-smithy-http", - "aws-smithy-json", + "aws-smithy-json 0.61.1", "aws-smithy-runtime", "aws-smithy-runtime-api", "aws-smithy-types", @@ -281,9 +281,9 @@ dependencies = [ [[package]] name = "aws-sdk-s3" -version = "1.63.0" +version = "1.65.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43850204a109a5eea1ea93951cf0440268cef98b0d27dfef4534949e23735f7" +checksum = "d3ba2c5c0f2618937ce3d4a5ad574b86775576fa24006bcb3128c6e2cbf3c34e" dependencies = [ "aws-credential-types", "aws-runtime", @@ -292,7 +292,7 @@ dependencies = [ "aws-smithy-checksums", "aws-smithy-eventstream", "aws-smithy-http", - "aws-smithy-json", + "aws-smithy-json 0.61.1", "aws-smithy-runtime", "aws-smithy-runtime-api", "aws-smithy-types", @@ -315,15 +315,15 @@ dependencies = [ [[package]] name = "aws-sdk-sqs" -version = "1.49.0" +version = "1.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "073df10a6d1dbbfdb06c5a6a6d1ebf5bf799afe64586e0688bae08a3b1be553f" +checksum = "1d0a1bb53c15b172e67d1ed2576514a998397f91205c475e3278125a98134732" dependencies = [ "aws-credential-types", "aws-runtime", "aws-smithy-async", "aws-smithy-http", - "aws-smithy-json", + "aws-smithy-json 0.61.1", "aws-smithy-runtime", "aws-smithy-runtime-api", "aws-smithy-types", @@ -345,7 +345,7 @@ dependencies = [ "aws-runtime", "aws-smithy-async", "aws-smithy-http", - "aws-smithy-json", + "aws-smithy-json 0.60.7", "aws-smithy-runtime", "aws-smithy-runtime-api", "aws-smithy-types", @@ -367,7 +367,7 @@ dependencies = [ "aws-runtime", "aws-smithy-async", "aws-smithy-http", - "aws-smithy-json", + "aws-smithy-json 0.60.7", "aws-smithy-runtime", "aws-smithy-runtime-api", "aws-smithy-types", @@ -389,7 +389,7 @@ dependencies = [ "aws-runtime", "aws-smithy-async", "aws-smithy-http", - "aws-smithy-json", + "aws-smithy-json 0.60.7", "aws-smithy-query", "aws-smithy-runtime", "aws-smithy-runtime-api", @@ -404,9 +404,9 @@ dependencies = [ [[package]] name = "aws-sigv4" -version = "1.2.5" +version = "1.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5619742a0d8f253be760bfbb8e8e8368c69e3587e4637af5754e488a611499b1" +checksum = "7d3820e0c08d0737872ff3c7c1f21ebbb6693d832312d6152bf18ef50a5471c2" dependencies = [ "aws-credential-types", "aws-smithy-eventstream", @@ -504,6 +504,15 @@ dependencies = [ "aws-smithy-types", ] +[[package]] +name = "aws-smithy-json" +version = "0.61.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee4e69cc50921eb913c6b662f8d909131bb3e6ad6cb6090d3a39b66fc5c52095" +dependencies = [ + "aws-smithy-types", +] + [[package]] name = "aws-smithy-query" version = "0.60.7" @@ -516,9 +525,9 @@ dependencies = [ [[package]] name = "aws-smithy-runtime" -version = "1.7.3" +version = "1.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be28bd063fa91fd871d131fc8b68d7cd4c5fa0869bea68daca50dcb1cbd76be2" +checksum = "9f20685047ca9d6f17b994a07f629c813f08b5bce65523e47124879e60103d45" dependencies = [ "aws-smithy-async", "aws-smithy-http", @@ -734,7 +743,7 @@ dependencies = [ [[package]] name = "bnaclient" version = "1.0.0" -source = "git+https://github.com/PeopleForBikes/bna-api?rev=f145e8b#f145e8b76c1554321514d90f8da25fb0690ca613" +source = "git+https://github.com/PeopleForBikes/bna-api?rev=c8ca326#c8ca32611e7239c7ac8c8b46fa3ee18a4881079c" dependencies = [ "bytes", "chrono", @@ -784,6 +793,7 @@ dependencies = [ "aws_lambda_events", "bnaclient", "bnacore", + "chrono", "csv", "fontdb 0.23.0", "heck", @@ -801,7 +811,6 @@ dependencies = [ "simple-error", "slug", "svg2pdf", - "time", "tokio", "tracing", "tracing-subscriber", @@ -4244,9 +4253,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.41.1" +version = "1.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22cfb5bee7a6a52939ca9224d6ac897bb669134078daa8735560897f69de4d33" +checksum = "5cec9b21b0450273377fc97bd4c33a8acffc8c996c987a7c5b319a0083707551" dependencies = [ "backtrace", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 65e17a2..5735043 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,12 +6,12 @@ resolver = "2" async-std = "1.13.0" aws_lambda_events = "0.15.0" aws-config = "1.5.10" -aws-sdk-ecs = "1.56.1" -aws-sdk-s3 = "1.63.0" -aws-sdk-sqs = "1.49.0" +aws-sdk-ecs = "1.57.0" +aws-sdk-s3 = "1.65.0" +aws-sdk-sqs = "1.50.0" aws-smithy-types-convert = "0.60.8" axum = "0.7.7" -bnaclient = { git = "https://github.com/PeopleForBikes/bna-api", rev = "f145e8b" } +bnaclient = { git = "https://github.com/PeopleForBikes/bna-api", rev = "c8ca326" } bnacore = { git = "https://github.com/PeopleForBikes/brokenspoke", rev = "c20ec31" } chrono = "0.4.19" clap = "4.5.20" @@ -29,7 +29,7 @@ lopdf = "0.34.0" minijinja = "2.5.0" nats = "0.25.0" once_cell = "1.20.2" -pyo3 = "0.23.1" +pyo3 = "0.23.3" regex = "1.11.1" reqwest = "0.12.8" rstest = "0.23.0" @@ -44,9 +44,8 @@ serde_with = "3.11.0" simple-error = "0.3.0" slug = "0.1.6" svg2pdf = "0.12.0" -thiserror = "2.0.3" -time = "0.3.34" -tokio = "1.41.1" +thiserror = "2.0.4" +tokio = "1.42.0" tower = "0.5.1" tower-cookies = "0.10.0" tower-http = "0.6.1" diff --git a/lambdas/Cargo.toml b/lambdas/Cargo.toml index 2ad2345..7ed4263 100644 --- a/lambdas/Cargo.toml +++ b/lambdas/Cargo.toml @@ -12,6 +12,7 @@ aws-smithy-types-convert = { workspace = true, features = ["convert-chrono"] } aws_lambda_events = { workspace = true } bnaclient = { workspace = true } bnacore = { workspace = true } +chrono = { workspace = true } csv = { workspace = true } fontdb = { workspace = true } heck = { workspace = true } @@ -34,7 +35,6 @@ serde_with = { workspace = true } simple-error = { workspace = true } slug = { workspace = true } svg2pdf = { workspace = true } -time = { workspace = true, features = ["macros", "serde-well-known"] } tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } tracing = { workspace = true, features = ["log"] } tracing-subscriber = { workspace = true, features = ["fmt"] } diff --git a/lambdas/src/bna-fargate-run.rs b/lambdas/src/bna-fargate-run.rs index df9241e..f3cd2b2 100644 --- a/lambdas/src/bna-fargate-run.rs +++ b/lambdas/src/bna-fargate-run.rs @@ -6,6 +6,7 @@ use aws_sdk_ecs::types::{ use bnaclient::types::{AnalysisPatch, AnalysisPost, StateMachineId, Step}; use bnacore::aws::get_aws_parameter_value; use bnalambdas::{create_service_account_bna_client, AnalysisParameters, Context, AWSS3}; +use chrono::Utc; use lambda_runtime::{run, service_fn, Error, LambdaEvent}; use serde::{Deserialize, Serialize}; use tracing::info; @@ -51,6 +52,7 @@ async fn function_handler(event: LambdaEvent) -> Result Result<(), Error> { #[cfg(test)] mod tests { - use bnalambdas::{create_authenticated_bna_client, AuthResponse}; - use uuid::Uuid; - use super::*; #[test] @@ -203,34 +202,4 @@ mod tests { }"#; let _deserialized = serde_json::from_str::(json_input).unwrap(); } - - // #[tokio::test] - // async fn test_create_pipeline() { - // let auth = AuthResponse { - // access_token: String::from(""), - // expires_in: 3600, - // token_type: String::from("Bearer"), - // }; - - // // Create an authenticated BNA client. - // let client_authd = create_authenticated_bna_client("https://api.peopleforbikes.xyz", &auth); - - // // Send the request. - // let p = client_authd - // .post_ratings_analyses() - // .body( - // AnalysisPost::builder() - // .state_machine_id(StateMachineId( - // Uuid::parse_str("fc009967-c4d0-416b-baee-93708ac80cbc").unwrap(), - // )) - // .step(Step::Analysis) - // .sqs_message( - // serde_json::to_string(r#"{"analysis_parameters": "test"}"#).unwrap(), - // ), - // ) - // .send() - // .await - // .unwrap(); - // dbg!(p); - // } } diff --git a/lambdas/src/bna-save-results.rs b/lambdas/src/bna-save-results.rs index c592ae4..4e4ec7d 100644 --- a/lambdas/src/bna-save-results.rs +++ b/lambdas/src/bna-save-results.rs @@ -356,10 +356,9 @@ async fn main() -> Result<(), Error> { #[cfg(test)] mod tests { - - use aws_sdk_s3::primitives::DateTime; - use super::*; + use aws_sdk_s3::primitives::DateTime; + use std::env; // use bnalambdas::AuthResponse; #[test] @@ -604,4 +603,51 @@ mod tests { dec!(0.0228333333333) ); } + + // #[tokio::test] + // async fn test_handler() { + // let json_input = r#"{ + // "analysis_parameters": { + // "country": "usa", + // "city": "santa rosa", + // "region": "new mexico", + // "fips_code": "3570670" + // }, + // "receipt_handle": "AQEBFo+wTTIZdCvaF2KtZN4ZolAGKeKVGSAhQ7BTA9MUirBT/8mprrHIOg8LuWi3LK9Lu1oFDd5GqVmzExGeHlVbmRA3HWd+vy11b1N4qVeHywvUJJT5/G/GVG2jimkHDa31893N0k2HIm2USSsN6Bqw0JI57ac0ymUWJxzkN9/yJQQXg2dmnNn3YuouzQTGpOJnMjv9UnZaHGVjZXV30IWjs9VzUZd9Wnl721B99pF9t1FUeYnAxShtNUZKzbfbNmSmwtKoE+SwohFL0k84cYkJUjgdXw9yEoT2+zEqeGWtU/oSGmbLorPWIiVYubPcwni1Q9KZROUDvBX7sPDwUeYxxhw9SBxz3y4Tg5hH7X99D4tDXbnRJR1v/0aBAs9h/ohfcEjoYmHdYqRL9r2t33SwYg==", + // "context": { + // "Execution": { + // "Id": "arn:aws:states:us-west-2:863246263227:execution:brokenspoke-analyzer:fd34f1d1-8009-44f1-9111-d3a2daf8a8fe", + // "Name": "fd34f1d1-8009-44f1-9111-d3a2daf8a8fe", + // "RoleArn": "arn:aws:iam::863246263227:role/BNAPipelineLambdaExecution", + // "StartTime": "+002024-04-11T03:05:31.843000000Z" + // }, + // "State": { + // "EnteredTime": "+002024-04-11T03:05:32.059000000Z", + // "Name": "BNAContext" + // }, + // "StateMachine": { + // "Id": "arn:aws:states:us-west-2:863246263227:stateMachine:brokenspoke-analyzer", + // "Name": "brokenspoke-analyzer" + // }, + // "Id": "9ff90cac-0cf5-4923-897f-4416df5e7328" + // }, + // "aws_s3": { + // "destination": "usa/new mexico/santa rosa/23.12.4" + // }, + // "fargate": { + // "ecs_cluster_arn": "arn:aws:ecs:us-west-2:863246263227:cluster/bna", + // "task_arn": "arn:aws:ecs:us-west-2:863246263227:task/bna/681690ef8bbb446a93e1324f113e75f0", + // "last_status": "STOPPED" + // } + // }"#; + // let payload = serde_json::from_str::(json_input).unwrap(); + // let mut context = lambda_runtime::Context::default(); + // context.request_id = "ID".to_string(); + + // env::set_var("BNA_API_HOSTNAME", "http://localhost:3000"); + // env::set_var("BNA_BUCKET", "bna-analyzer"); + + // let event = LambdaEvent::new(payload, context); + // function_handler(event).await.unwrap(); + // } } diff --git a/lambdas/src/bna-teardown.rs b/lambdas/src/bna-teardown.rs index 2b5dc96..8a020ee 100644 --- a/lambdas/src/bna-teardown.rs +++ b/lambdas/src/bna-teardown.rs @@ -63,6 +63,7 @@ async fn main() -> Result<(), Error> { mod tests { use super::*; use bnalambdas::{Execution, State, StateMachine}; + use chrono::Utc; use lambda_runtime::{Context, LambdaEvent}; use uuid::Uuid; @@ -83,10 +84,10 @@ mod tests { id: "id".to_string(), name: "name".to_string(), role_arn: "arn".to_string(), - start_time: time::OffsetDateTime::now_utc(), + start_time: Utc::now(), }, state: State { - entered_time: time::OffsetDateTime::now_utc(), + entered_time: Utc::now(), name: "name".to_string(), }, state_machine: StateMachine { diff --git a/lambdas/src/lib.rs b/lambdas/src/lib.rs index 982de90..ba11670 100644 --- a/lambdas/src/lib.rs +++ b/lambdas/src/lib.rs @@ -1,8 +1,8 @@ use bnacore::aws::{get_aws_parameter_value, get_aws_secrets_value}; +use chrono::{DateTime, Utc}; use lambda_runtime::Error; use reqwest::blocking::Client; use serde::{Deserialize, Serialize}; -use time::OffsetDateTime; use uuid::Uuid; pub const BROKENSPOKE_ANALYZER_BUCKET: &str = "brokenspoke-analyzer"; @@ -138,8 +138,7 @@ pub struct Execution { pub id: String, pub name: String, pub role_arn: String, - #[serde(with = "time::serde::iso8601")] - pub start_time: OffsetDateTime, + pub start_time: DateTime, } impl Execution { @@ -177,8 +176,7 @@ impl Execution { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct State { - #[serde(with = "time::serde::iso8601")] - pub entered_time: OffsetDateTime, + pub entered_time: DateTime, pub name: String, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -277,7 +275,7 @@ mod tests { id: "id".to_string(), name: name.clone(), role_arn: "role".to_string(), - start_time: time::OffsetDateTime::now_utc(), + start_time: Utc::now(), }; let (state_machine_id, schedule_trigger_id) = deserialized.ids().unwrap(); assert_eq!(state_machine_id, Uuid::parse_str(&name).unwrap());