Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (5.6k points)

Providing the code, I'm running in AWS lambda function 

exports.handler = (event, context, callback) => {

            // 

          mqfunc1(func2);

};

var func2 = function(data) {

            console.log('got data: '+data);

};

var mqfunc1 = function(callback) {

        var myCallback = function(data) {

        console.log('got data: '+data);

        };

        var usingItNow = function(callback) {

        callback('get it?');

        };

};

How could I print the same message using callback function within the exports.handler?

1 Answer

0 votes
by (12.4k points)

You can try this:

callback(response_error, response_success)

Sample:

const response_success = {

      statusCode: 200,

      body: JSON.stringify({

        message: 'ok'

      }),

};

const response_error = {

    statusCode: 400,

    body: JSON.stringify({

        message: 'error'

    }),

};

if (error) {

   callback(response_error)

} else {

   callback(undefined, response_success)

}

For more information visit: aws lambda tutorial

Want to know more about AWS, Come & join: AWS Certification

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
0 votes
1 answer
asked Nov 3, 2020 in AWS by Sudhir_1997 (55.6k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...