By using AWS re:Post, you agree to the Terms of Use

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


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-

public int lambdaOcr(String filePath, String fileName, Long fileId, String destination, FileModel fileModel) throws Exception {

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 6 months ago27 views
1 Answer


I am not an expert on java, but I can advise you to use AWS EventBridge rules to schedule your lambda functions. (

answered 6 months 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