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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠