From 778ccc91acd711e030f109320ceec346eeb5b5c1 Mon Sep 17 00:00:00 2001 From: Eric Ghildyal Date: Mon, 2 Dec 2024 18:18:47 -0500 Subject: [PATCH] Small refactoring --- src/adapters/ingresses/apig.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/adapters/ingresses/apig.rs b/src/adapters/ingresses/apig.rs index aaa2dc7..7e84a38 100644 --- a/src/adapters/ingresses/apig.rs +++ b/src/adapters/ingresses/apig.rs @@ -86,7 +86,7 @@ impl AwsApiGateway { } /// Helper function to convert an API Gateway's name to its auto-generated AWS ID - pub async fn get_resource_id_by_name( + pub async fn get_resource_id_by_path( &self, api_id: &str, resource_name: &str, @@ -133,7 +133,7 @@ impl Ingress for AwsApiGateway { let function_code = FunctionCode::builder().zip_file(code).build(); let zip_file = function_code .zip_file() - .ok_or(miette!("Couldn't zip lambda code"))?; + .ok_or(miette!("Couldn't zip Lambda code"))?; // Upload it to Lambda and ensure to create a new version let lambda_res = self @@ -149,10 +149,18 @@ impl Ingress for AwsApiGateway { // NOTE: this ARN includes the new version number appended to the end let lambda_arn = lambda_res .function_arn() - .ok_or(miette!("Couldn't get ARN of deployed lambda"))?; + .ok_or(miette!("Couldn't get ARN of deployed Lambda"))?; + // Get the auto-generated API ID and Resource ID let api = self.get_api_id_by_name(&self.gateway_name).await?; - let api_id = api.id().ok_or(miette!("Couldn't get ID of deployed API"))?; + let api_id = api.id().ok_or(miette!("Couldn't get ID of API Gateway"))?; + + let resource = self + .get_resource_id_by_path(api_id, &self.resource_path) + .await?; + let resource_id = resource + .id() + .ok_or(miette!("Couldn't get ID of API Gateway Resource"))?; // Ensure we add invoke permissions to the new version of the lambda // NOTE: All calls to invoke the function will fail unless this is explicitly added @@ -166,6 +174,7 @@ impl Ingress for AwsApiGateway { .await .into_diagnostic()?; + // Update our API Gateway to point at our new lambda version let patch_op = PatchOperation::builder() .op(Op::Replace) .path("/uri") @@ -175,14 +184,6 @@ impl Ingress for AwsApiGateway { )) .build(); - let resource = self - .get_resource_id_by_name(api_id, &self.resource_path) - .await?; - let resource_id = resource - .id() - .ok_or(miette!("Couldn't get ID of Resource"))?; - - // Next, we need to update our API Gateway to point at our new lambda version self.apig_client .update_integration() .rest_api_id(api_id)