Lambda function is not getting invoked if I call it inside a cronjob method or in a scheduler

0

Hi,I have a cron job method-

@Scheduled( cron = "* * * * * *", zone = "Asia/Calcutta" )
    public void  fetchUnOcredFilesAndTriggerLambda()  {

 {
   ...     
            int totalNoOfPages = invokeLambdaFunctionAsync.lambdaOcr(fileModel.getAbsolutePath(), fileModel.getFileName(), fileModel.getId(), destination, fileModel);
   ..         
    }

the lambdaOcr() method does some minor processing and then calls the invokeAsync(req) method-https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/basics-async.html

public int lambdaOcr(String filePath, String fileName, Long fileId, String destination, FileModel fileModel) throws Exception {
....
....
             lambda.invokeAsync(req);
....
....
}

The problem I am facing here is the lambda.invokeAsync(req); is not getting invoked if I use the above cron job. I checked the console cloud watch logs and saw that no logs are coming. BUT If I try to invoke by creating the main method and passing the hard-coded inputs inside the fetchUnOcredFilesAndTriggerLambda() method to call the invokeLambdaFunctionAsync.lambdaOcr(<-hard-coded inputs->), the Lambda function gets invoked and I get the correct output. But I dont want to hard code the inputs and want to invoke the invokeLambdaFunctionAsync.lambdaOcr() using the cron job. But with the cron job, Lambda function is simply not getting invoked.I also tried to replacing @Scheduled( cron = " * * * * ", zone = "Asia/Calcutta" ) with @Scheduled( fixedDelay = 30000 ) but not getting any results. Please can anyone tell me where I am going wrong? How to use the cron job to invoke the Lambda function? I am doing this in Spring boot and Java and new to AWS Lambda. Any help appreciated...thanks.

已提問 2 年前檢視次數 431 次
1 個回答
0

Hello;

I am not an expert on java, but I can advise you to use AWS EventBridge rules to schedule your lambda functions. (https://us-west-2.console.aws.amazon.com/events/home?region=us-west-2#/rules)

bbolek
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南