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.

asked 2 years ago415 views
1 Answer
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
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions