mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-04 14:07:18 +08:00 
			
		
		
		
	Co-authored-by: harsh_sharma_juspay <harsh.sharma@juspay.in> Co-authored-by: Ivor Dsouza <ivor.dsouza@juspay.in> Co-authored-by: Chethan Rao <70657455+Chethan-rao@users.noreply.github.com> Co-authored-by: nain-F49FF806 <126972030+nain-F49FF806@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: akshay.s <akshay.s@juspay.in> Co-authored-by: Gnanasundari24 <118818938+Gnanasundari24@users.noreply.github.com>
		
			
				
	
	
		
			37 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
use aws_config::{self, meta::region::RegionProviderChain};
 | 
						|
use aws_sdk_lambda::{config::Region, types::InvocationType::Event, Client};
 | 
						|
use aws_smithy_types::Blob;
 | 
						|
use common_utils::errors::CustomResult;
 | 
						|
use error_stack::{IntoReport, ResultExt};
 | 
						|
 | 
						|
use crate::errors::AnalyticsError;
 | 
						|
 | 
						|
async fn get_aws_client(region: String) -> Client {
 | 
						|
    let region_provider = RegionProviderChain::first_try(Region::new(region));
 | 
						|
    let sdk_config = aws_config::from_env().region(region_provider).load().await;
 | 
						|
    Client::new(&sdk_config)
 | 
						|
}
 | 
						|
 | 
						|
pub async fn invoke_lambda(
 | 
						|
    function_name: &str,
 | 
						|
    region: &str,
 | 
						|
    json_bytes: &[u8],
 | 
						|
) -> CustomResult<(), AnalyticsError> {
 | 
						|
    get_aws_client(region.to_string())
 | 
						|
        .await
 | 
						|
        .invoke()
 | 
						|
        .function_name(function_name)
 | 
						|
        .invocation_type(Event)
 | 
						|
        .payload(Blob::new(json_bytes.to_owned()))
 | 
						|
        .send()
 | 
						|
        .await
 | 
						|
        .into_report()
 | 
						|
        .map_err(|er| {
 | 
						|
            let er_rep = format!("{er:?}");
 | 
						|
            er.attach_printable(er_rep)
 | 
						|
        })
 | 
						|
        .change_context(AnalyticsError::UnknownError)
 | 
						|
        .attach_printable("Lambda invocation failed")?;
 | 
						|
    Ok(())
 | 
						|
}
 |