Sunday, 7 May 2017

variable is null after returned from lambda function in AWS

I tried to define local variable then call lambda function which populate the value to my local variable:

var listOfAliases = null;
lambda.invoke(params, function(err, data) {
                    if (err) {
                      //context.fail(err);
                      console.log(`This is the ERROR execution =${err} =================================`);
                      prompt(err);
                    } else {
                      //context.succeed('Data loaded from DB: '+ data.Payload);
                      listOfAliases = JSON.stringify(data.Payload);
                      console.log(`This is the VALIDE execution =${data.Payload} =================================`);   //I can see this in the log with proper values
                      console.log(`This is the VALIDE execution(listOfAliases) =${listOfAliases} =================================`);   //I can see this in the log with proper values

                    }
                    callback(null, JSON.parse(data.Payload));
                  });

            console.log(`This is the DB execution listOfAliases=${listOfAliases} =================================`); //I can see this in the log with NULL value



via Ahmed Aziz

No comments:

Post a Comment