AWS lambda returning undefined instead of the value

I am trying to listen for events on the polygon blockchain, I am new to JavaScript and don’t quite understand how promises work.I have a module that reads from the blockchain, which does give me the correct answer with a setTimeout function, however, if I do the same thing from the aws export.handler I get undefined. Anyone can help me with this?

My blockChainScanner code:
async function Scanner(callback){

let options = {

    fromBlock:24262239,                  //Number || "earliest" || "pending" || "latest"

    toBlock: 'latest'






.then(events => {

     if(events.length != 0) {

        //need a for loop to iterate over all events

        callback( events[0];



         console.log("No event to Display")




.catch(err => {




async function main(){

const result = Scanner(response =>{

    exports.ID = response;




exports.main = main;


My code for AWS lambda:

const AWS = require(‘aws-sdk’);

AWS.config.update({ region: “us-east-1”});

//let dynamodbLambda = new AWS.Lambda({region: “us-east-1”})

let BCScanner = require("./blockChainScanner");

console.log(“Token ID:” + BCScanner.ID);

exports.handler = async function(event, context, callback) {

let result = await BCScanner.main()

.then(() =>{

    setTimeout(() =>{

        console.log("Token ID:" + BCScanner.ID);

        return BCScanner.ID;