1717//! This module provides functionality to automatically deploy or update
1818//! the Lambda function used for leaf search operations.
1919
20- #[ cfg( feature = "auto-deploy" ) ]
2120use std:: collections:: HashMap ;
2221
2322use aws_sdk_lambda:: Client as LambdaClient ;
24- #[ cfg( feature = "auto-deploy" ) ]
2523use aws_sdk_lambda:: error:: SdkError ;
26- #[ cfg( feature = "auto-deploy" ) ]
2724use aws_sdk_lambda:: operation:: create_function:: CreateFunctionError ;
28- #[ cfg( feature = "auto-deploy" ) ]
2925use aws_sdk_lambda:: operation:: get_function:: GetFunctionOutput ;
30- #[ cfg( feature = "auto-deploy" ) ]
3126use aws_sdk_lambda:: primitives:: Blob ;
32- #[ cfg( feature = "auto-deploy" ) ]
3327use aws_sdk_lambda:: types:: { Architecture , Environment , FunctionCode , Runtime } ;
34- # [ cfg ( feature = "auto-deploy" ) ]
28+ use quickwit_config :: LambdaDeployConfig ;
3529use tracing:: { debug, info, warn} ;
3630
3731use crate :: config:: LambdaDeployConfig ;
3832use crate :: error:: { LambdaError , LambdaResult } ;
3933
4034/// Embedded Lambda binary (arm64, compressed).
4135/// This is included at compile time when the `auto-deploy` feature is enabled.
42- #[ cfg( feature = "auto-deploy" ) ]
4336const LAMBDA_BINARY : & [ u8 ] = include_bytes ! ( concat!( env!( "OUT_DIR" ) , "/lambda_bootstrap.zip" ) ) ;
4437
4538/// Version tag key used to track deployed Quickwit version.
46- #[ cfg( feature = "auto-deploy" ) ]
4739const VERSION_TAG_KEY : & str = "quickwit_version" ;
4840
4941/// Description prefix for auto-deployed Lambda functions.
50- #[ cfg( feature = "auto-deploy" ) ]
5142const FUNCTION_DESCRIPTION : & str = "Quickwit Lambda leaf search handler" ;
5243
5344/// Lambda function deployer.
5445///
5546/// Handles creating and updating Lambda functions for the auto-deploy feature.
5647/// Safe for concurrent calls from multiple Quickwit nodes - CreateFunction is idempotent.
5748pub struct LambdaDeployer {
58- #[ allow( dead_code) ]
5949 client : LambdaClient ,
6050}
6151
@@ -68,7 +58,6 @@ impl LambdaDeployer {
6858 }
6959
7060 /// Create a new Lambda deployer with a custom client.
71- #[ allow( dead_code) ]
7261 pub fn with_client ( client : LambdaClient ) -> Self {
7362 Self { client }
7463 }
@@ -77,7 +66,6 @@ impl LambdaDeployer {
7766 ///
7867 /// Safe for concurrent calls from multiple Quickwit nodes - CreateFunction is idempotent.
7968 /// Returns the function ARN.
80- #[ cfg( feature = "auto-deploy" ) ]
8169 pub async fn deploy (
8270 & self ,
8371 function_name : & str ,
@@ -114,24 +102,13 @@ impl LambdaDeployer {
114102 }
115103 }
116104
117- /// Deploy is a no-op when auto-deploy feature is not enabled.
118- #[ cfg( not( feature = "auto-deploy" ) ) ]
119- pub async fn deploy (
120- & self ,
121- _function_name : & str ,
122- _deploy_config : & LambdaDeployConfig ,
123- ) -> LambdaResult < String > {
124- Err ( LambdaError :: Configuration (
125- "auto-deploy feature is not enabled at compile time" . into ( ) ,
126- ) )
127- }
105+
128106
129107 /// Create the Lambda function.
130108 ///
131109 /// Note: CreateFunction is idempotent - if the function already exists, AWS returns
132110 /// ResourceConflictException. Multiple Quickwit nodes starting simultaneously is safe;
133111 /// one will succeed and others will fall back to update_function.
134- #[ cfg( feature = "auto-deploy" ) ]
135112 async fn create_function (
136113 & self ,
137114 name : & str ,
@@ -199,7 +176,6 @@ impl LambdaDeployer {
199176 ///
200177 /// Compares the deployed version tag with the current Quickwit version
201178 /// and updates if they differ.
202- #[ cfg( feature = "auto-deploy" ) ]
203179 async fn update_function_if_needed (
204180 & self ,
205181 name : & str ,
@@ -278,7 +254,6 @@ impl LambdaDeployer {
278254 }
279255
280256 /// Wait for function update to complete.
281- #[ cfg( feature = "auto-deploy" ) ]
282257 async fn wait_for_update_complete ( & self , name : & str ) -> LambdaResult < ( ) > {
283258 // Poll until the function state is Active and LastUpdateStatus is Successful
284259 for _ in 0 ..60 {
@@ -319,7 +294,6 @@ impl LambdaDeployer {
319294 }
320295
321296 /// Check if the function needs to be updated based on version tag.
322- #[ cfg( feature = "auto-deploy" ) ]
323297 fn needs_update ( & self , existing : & GetFunctionOutput ) -> bool {
324298 let current_version = env ! ( "CARGO_PKG_VERSION" ) ;
325299
@@ -370,7 +344,6 @@ impl LambdaDeployer {
370344 }
371345
372346 /// Build environment variables for the Lambda function.
373- #[ cfg( feature = "auto-deploy" ) ]
374347 fn build_environment ( & self ) -> Environment {
375348 let mut env_vars = HashMap :: new ( ) ;
376349 // Set reasonable defaults for logging
@@ -381,7 +354,6 @@ impl LambdaDeployer {
381354 }
382355
383356 /// Build tags for the Lambda function.
384- #[ cfg( feature = "auto-deploy" ) ]
385357 fn build_tags ( & self ) -> HashMap < String , String > {
386358 let mut tags = HashMap :: new ( ) ;
387359 tags. insert (
@@ -393,7 +365,17 @@ impl LambdaDeployer {
393365 }
394366}
395367
396- #[ cfg( all( test, feature = "auto-deploy" ) ) ]
368+ pub async fn deploy (
369+ function_name : & str ,
370+ deploy_config : & LambdaDeployConfig ,
371+ ) -> LambdaResult < String > {
372+ let lambda_deployer = LambdaDeployer :: new ( ) . await ?;
373+ let lambda_arn = lambda_deployer. deploy ( function_name, deploy_config) . await ?;
374+ info ! ( "successfully deployed lambda function `{}`" , lambda_arn) ;
375+ Ok ( lambda_arn)
376+ }
377+
378+ #[ cfg( test) ]
397379mod tests {
398380 use super :: * ;
399381
0 commit comments