Skip to content

Commit

Permalink
Fix Fargate run lambda
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rgreinho committed Dec 7, 2024
1 parent b49a196 commit 6f98452
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 77 deletions.
57 changes: 33 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lambdas/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"] }
Expand Down
35 changes: 2 additions & 33 deletions lambdas/src/bna-fargate-run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,6 +52,7 @@ async fn function_handler(event: LambdaEvent<TaskInput>) -> Result<TaskOutput, E
.body(
AnalysisPost::builder()
.state_machine_id(StateMachineId(state_machine_id))
.start_time(Utc::now())
.step(Step::Setup)
.sqs_message(serde_json::to_string(analysis_parameters)?),
)
Expand Down Expand Up @@ -164,9 +166,6 @@ async fn main() -> Result<(), Error> {

#[cfg(test)]
mod tests {
use bnalambdas::{create_authenticated_bna_client, AuthResponse};
use uuid::Uuid;

use super::*;

#[test]
Expand Down Expand Up @@ -203,34 +202,4 @@ mod tests {
}"#;
let _deserialized = serde_json::from_str::<TaskInput>(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);
// }
}
52 changes: 49 additions & 3 deletions lambdas/src/bna-save-results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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::<TaskInput>(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();
// }
}
5 changes: 3 additions & 2 deletions lambdas/src/bna-teardown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand Down
Loading

0 comments on commit 6f98452

Please sign in to comment.