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年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ