AWS Lambda promise with callback issue











up vote
0
down vote

favorite












I am using mail-confirm to validate an email address and the Lambda function is returning rather than waiting for the promise result on




email.check().then(results=>{




And jumps straight to




console.log('callback issue');




and returns. I would expect the email check to finish and return the results object inside of the callback. Instead the function is returned before the promise can resolve. Any pointers will be appreciated.



Function example:



const MailConfirm = require('mail-confirm');
const isemail = require('isemail');

module.exports.app = async (event, context) => {
let request = JSON.parse(event.body)


if(request.email){
var emailToValidate = request.email
if(isemail.validate(emailToValidate)){
console.log(`${emailToValidate} - stage 1 pass`);

const email = new MailConfirm({
emailAddress: emailToValidate,
timeout: 2000,
invalidMailboxKeywords: ['noreply', 'noemail']
});

//Promise issue
email.check().then(results=>{
console.log(results);
return {
statusCode: 200,
body: JSON.stringify({
validatedEmail: emailToValidate,
isValid: true,
}),
};
}).catch(err=>{
console.log(`${emailToValidate} stage 2/3 failed`)
return {
statusCode: 200,
body: JSON.stringify({
validatedEmail: emailToValidate,
isValid: false,
message: err,
}),
};
});
//Returns here
console.log('callback issue');
}else{
return {
statusCode: 200,
body: JSON.stringify({
validatedEmail: emailToValidate,
isValid: false,
message: 'Failed stage 1 validation',
}),
};
}
}

// return {
// statusCode: 500,
// body: JSON.stringify({
// message: 'Something went wrong.',
// }),
// };
};


EDIT:



Thanks everyone for your responses. I have implemented the await and it is working nicely when testing




test@gmail.com




. However if i validate




test@email.com




the email.check() function doesn't return and my lambda function returns with a blank response (502 to API gateway). I am no sure what happens after let results = await email.check(); when validating test@email.com. My Lambada function is not timing out.



 try{
let results = await email.check();
console.log(results);
//Returns ok on test@gmail.com
return {
statusCode: 200,
body: JSON.stringify({
validatedEmail: emailToValidate,
isValid: true,
}),
};
} catch(err){
console.log(`${emailToValidate} stage 2/3 failed`)
return {
statusCode: 200,
body: JSON.stringify({
validatedEmail: emailToValidate,
isValid: false,
message: err,
}),
};
}


Lambda logs

START Version: $LATEST
test@email.com - stage 1 pass
END
REPORT Duration: 647.88 ms Billed Duration: 700 ms Memory Size: 128 MB Max Memory Used: 21 MB



API Gateway 502 Bad Gateway (Due to the Lambda function response being null)

{
"message": "Internal server error"
}

EDIT 2:



It turns out i am getting a 554 error in mail-confirm when validating test@email.com.










share|improve this question
























  • not found result on console.log(results); and console.log(${emailToValidate} stage 2/3 failed)?
    – Pyae Phyoe Shein
    Nov 10 at 14:19

















up vote
0
down vote

favorite












I am using mail-confirm to validate an email address and the Lambda function is returning rather than waiting for the promise result on




email.check().then(results=>{




And jumps straight to




console.log('callback issue');




and returns. I would expect the email check to finish and return the results object inside of the callback. Instead the function is returned before the promise can resolve. Any pointers will be appreciated.



Function example:



const MailConfirm = require('mail-confirm');
const isemail = require('isemail');

module.exports.app = async (event, context) => {
let request = JSON.parse(event.body)


if(request.email){
var emailToValidate = request.email
if(isemail.validate(emailToValidate)){
console.log(`${emailToValidate} - stage 1 pass`);

const email = new MailConfirm({
emailAddress: emailToValidate,
timeout: 2000,
invalidMailboxKeywords: ['noreply', 'noemail']
});

//Promise issue
email.check().then(results=>{
console.log(results);
return {
statusCode: 200,
body: JSON.stringify({
validatedEmail: emailToValidate,
isValid: true,
}),
};
}).catch(err=>{
console.log(`${emailToValidate} stage 2/3 failed`)
return {
statusCode: 200,
body: JSON.stringify({
validatedEmail: emailToValidate,
isValid: false,
message: err,
}),
};
});
//Returns here
console.log('callback issue');
}else{
return {
statusCode: 200,
body: JSON.stringify({
validatedEmail: emailToValidate,
isValid: false,
message: 'Failed stage 1 validation',
}),
};
}
}

// return {
// statusCode: 500,
// body: JSON.stringify({
// message: 'Something went wrong.',
// }),
// };
};


EDIT:



Thanks everyone for your responses. I have implemented the await and it is working nicely when testing




test@gmail.com




. However if i validate




test@email.com




the email.check() function doesn't return and my lambda function returns with a blank response (502 to API gateway). I am no sure what happens after let results = await email.check(); when validating test@email.com. My Lambada function is not timing out.



 try{
let results = await email.check();
console.log(results);
//Returns ok on test@gmail.com
return {
statusCode: 200,
body: JSON.stringify({
validatedEmail: emailToValidate,
isValid: true,
}),
};
} catch(err){
console.log(`${emailToValidate} stage 2/3 failed`)
return {
statusCode: 200,
body: JSON.stringify({
validatedEmail: emailToValidate,
isValid: false,
message: err,
}),
};
}


Lambda logs

START Version: $LATEST
test@email.com - stage 1 pass
END
REPORT Duration: 647.88 ms Billed Duration: 700 ms Memory Size: 128 MB Max Memory Used: 21 MB



API Gateway 502 Bad Gateway (Due to the Lambda function response being null)

{
"message": "Internal server error"
}

EDIT 2:



It turns out i am getting a 554 error in mail-confirm when validating test@email.com.










share|improve this question
























  • not found result on console.log(results); and console.log(${emailToValidate} stage 2/3 failed)?
    – Pyae Phyoe Shein
    Nov 10 at 14:19















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am using mail-confirm to validate an email address and the Lambda function is returning rather than waiting for the promise result on




email.check().then(results=>{




And jumps straight to




console.log('callback issue');




and returns. I would expect the email check to finish and return the results object inside of the callback. Instead the function is returned before the promise can resolve. Any pointers will be appreciated.



Function example:



const MailConfirm = require('mail-confirm');
const isemail = require('isemail');

module.exports.app = async (event, context) => {
let request = JSON.parse(event.body)


if(request.email){
var emailToValidate = request.email
if(isemail.validate(emailToValidate)){
console.log(`${emailToValidate} - stage 1 pass`);

const email = new MailConfirm({
emailAddress: emailToValidate,
timeout: 2000,
invalidMailboxKeywords: ['noreply', 'noemail']
});

//Promise issue
email.check().then(results=>{
console.log(results);
return {
statusCode: 200,
body: JSON.stringify({
validatedEmail: emailToValidate,
isValid: true,
}),
};
}).catch(err=>{
console.log(`${emailToValidate} stage 2/3 failed`)
return {
statusCode: 200,
body: JSON.stringify({
validatedEmail: emailToValidate,
isValid: false,
message: err,
}),
};
});
//Returns here
console.log('callback issue');
}else{
return {
statusCode: 200,
body: JSON.stringify({
validatedEmail: emailToValidate,
isValid: false,
message: 'Failed stage 1 validation',
}),
};
}
}

// return {
// statusCode: 500,
// body: JSON.stringify({
// message: 'Something went wrong.',
// }),
// };
};


EDIT:



Thanks everyone for your responses. I have implemented the await and it is working nicely when testing




test@gmail.com




. However if i validate




test@email.com




the email.check() function doesn't return and my lambda function returns with a blank response (502 to API gateway). I am no sure what happens after let results = await email.check(); when validating test@email.com. My Lambada function is not timing out.



 try{
let results = await email.check();
console.log(results);
//Returns ok on test@gmail.com
return {
statusCode: 200,
body: JSON.stringify({
validatedEmail: emailToValidate,
isValid: true,
}),
};
} catch(err){
console.log(`${emailToValidate} stage 2/3 failed`)
return {
statusCode: 200,
body: JSON.stringify({
validatedEmail: emailToValidate,
isValid: false,
message: err,
}),
};
}


Lambda logs

START Version: $LATEST
test@email.com - stage 1 pass
END
REPORT Duration: 647.88 ms Billed Duration: 700 ms Memory Size: 128 MB Max Memory Used: 21 MB



API Gateway 502 Bad Gateway (Due to the Lambda function response being null)

{
"message": "Internal server error"
}

EDIT 2:



It turns out i am getting a 554 error in mail-confirm when validating test@email.com.










share|improve this question















I am using mail-confirm to validate an email address and the Lambda function is returning rather than waiting for the promise result on




email.check().then(results=>{




And jumps straight to




console.log('callback issue');




and returns. I would expect the email check to finish and return the results object inside of the callback. Instead the function is returned before the promise can resolve. Any pointers will be appreciated.



Function example:



const MailConfirm = require('mail-confirm');
const isemail = require('isemail');

module.exports.app = async (event, context) => {
let request = JSON.parse(event.body)


if(request.email){
var emailToValidate = request.email
if(isemail.validate(emailToValidate)){
console.log(`${emailToValidate} - stage 1 pass`);

const email = new MailConfirm({
emailAddress: emailToValidate,
timeout: 2000,
invalidMailboxKeywords: ['noreply', 'noemail']
});

//Promise issue
email.check().then(results=>{
console.log(results);
return {
statusCode: 200,
body: JSON.stringify({
validatedEmail: emailToValidate,
isValid: true,
}),
};
}).catch(err=>{
console.log(`${emailToValidate} stage 2/3 failed`)
return {
statusCode: 200,
body: JSON.stringify({
validatedEmail: emailToValidate,
isValid: false,
message: err,
}),
};
});
//Returns here
console.log('callback issue');
}else{
return {
statusCode: 200,
body: JSON.stringify({
validatedEmail: emailToValidate,
isValid: false,
message: 'Failed stage 1 validation',
}),
};
}
}

// return {
// statusCode: 500,
// body: JSON.stringify({
// message: 'Something went wrong.',
// }),
// };
};


EDIT:



Thanks everyone for your responses. I have implemented the await and it is working nicely when testing




test@gmail.com




. However if i validate




test@email.com




the email.check() function doesn't return and my lambda function returns with a blank response (502 to API gateway). I am no sure what happens after let results = await email.check(); when validating test@email.com. My Lambada function is not timing out.



 try{
let results = await email.check();
console.log(results);
//Returns ok on test@gmail.com
return {
statusCode: 200,
body: JSON.stringify({
validatedEmail: emailToValidate,
isValid: true,
}),
};
} catch(err){
console.log(`${emailToValidate} stage 2/3 failed`)
return {
statusCode: 200,
body: JSON.stringify({
validatedEmail: emailToValidate,
isValid: false,
message: err,
}),
};
}


Lambda logs

START Version: $LATEST
test@email.com - stage 1 pass
END
REPORT Duration: 647.88 ms Billed Duration: 700 ms Memory Size: 128 MB Max Memory Used: 21 MB



API Gateway 502 Bad Gateway (Due to the Lambda function response being null)

{
"message": "Internal server error"
}

EDIT 2:



It turns out i am getting a 554 error in mail-confirm when validating test@email.com.







node.js aws-lambda






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 4:22

























asked Nov 10 at 5:42









Sean

187




187












  • not found result on console.log(results); and console.log(${emailToValidate} stage 2/3 failed)?
    – Pyae Phyoe Shein
    Nov 10 at 14:19




















  • not found result on console.log(results); and console.log(${emailToValidate} stage 2/3 failed)?
    – Pyae Phyoe Shein
    Nov 10 at 14:19


















not found result on console.log(results); and console.log(${emailToValidate} stage 2/3 failed)?
– Pyae Phyoe Shein
Nov 10 at 14:19






not found result on console.log(results); and console.log(${emailToValidate} stage 2/3 failed)?
– Pyae Phyoe Shein
Nov 10 at 14:19














3 Answers
3






active

oldest

votes

















up vote
0
down vote



accepted










You need to do some reading but basically anything in a async function that returns a promise you can await like so



module.exports.app = async (event, context, callback) => {
try {
const results = await SomeClass.somePromise()

const anotherResult = await SomeOtherClass.somePromise()

// do some stuff

callback(null, some_valid_http_response)


} catch (e) [

callback(e, null) // or handle another way
}
}


In short you dont await somePromise.then you just await the promise.



If you want to save yourself a whole world of hurt switch to Node 8.10 you can use most of the latest ES6 features, just make sure you use:



const someLib = require('whatever)


rather than import!






share|improve this answer




























    up vote
    0
    down vote













    Your function is async, email.check().then(...) returns a promise which is never awaited on your side. Remove async at your lambda handler or await await email.check().then(...) the returned promise. If you remove async you have to use the callback property of lambda.






    share|improve this answer






























      up vote
      0
      down vote













      Any method that is "thenable" is considered a Promise and will execute asynchronously. Therefore, email.check() is being invoked as a Promise and will not block code execution, which results in console.log() being invoked before you get a response. Since you're already using async/await in your lambda handler, you can just await for the response from email.check() before continuing.



      let resp = await email.check().then(results=>{
      console.log(results);
      return {
      statusCode: 200,
      body: JSON.stringify({
      validatedEmail: emailToValidate,
      isValid: true,
      }),
      };
      })

      console.log( resp ); // outputs object returned from email.check()





      share|improve this answer





















      • Await and then doesn't really make sense buddy.
        – Mrk Fldig
        Nov 11 at 20:44










      • @MrkFldig async/await returns a Promise, which means it is thenable. After all, it is simply just a wrapper around native Promises and they can be used together with no issues. Give it a try.
        – putipong
        Nov 12 at 19:18












      • Simply put I'd reject any PR that used await somePromise.then() it's almost an antipattern. There are reasons for doing it, for example mysql lib returns (err, results) but you can still wrap that in a function to return the right object.
        – Mrk Fldig
        Nov 12 at 19:23











      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236315%2faws-lambda-promise-with-callback-issue%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote



      accepted










      You need to do some reading but basically anything in a async function that returns a promise you can await like so



      module.exports.app = async (event, context, callback) => {
      try {
      const results = await SomeClass.somePromise()

      const anotherResult = await SomeOtherClass.somePromise()

      // do some stuff

      callback(null, some_valid_http_response)


      } catch (e) [

      callback(e, null) // or handle another way
      }
      }


      In short you dont await somePromise.then you just await the promise.



      If you want to save yourself a whole world of hurt switch to Node 8.10 you can use most of the latest ES6 features, just make sure you use:



      const someLib = require('whatever)


      rather than import!






      share|improve this answer

























        up vote
        0
        down vote



        accepted










        You need to do some reading but basically anything in a async function that returns a promise you can await like so



        module.exports.app = async (event, context, callback) => {
        try {
        const results = await SomeClass.somePromise()

        const anotherResult = await SomeOtherClass.somePromise()

        // do some stuff

        callback(null, some_valid_http_response)


        } catch (e) [

        callback(e, null) // or handle another way
        }
        }


        In short you dont await somePromise.then you just await the promise.



        If you want to save yourself a whole world of hurt switch to Node 8.10 you can use most of the latest ES6 features, just make sure you use:



        const someLib = require('whatever)


        rather than import!






        share|improve this answer























          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          You need to do some reading but basically anything in a async function that returns a promise you can await like so



          module.exports.app = async (event, context, callback) => {
          try {
          const results = await SomeClass.somePromise()

          const anotherResult = await SomeOtherClass.somePromise()

          // do some stuff

          callback(null, some_valid_http_response)


          } catch (e) [

          callback(e, null) // or handle another way
          }
          }


          In short you dont await somePromise.then you just await the promise.



          If you want to save yourself a whole world of hurt switch to Node 8.10 you can use most of the latest ES6 features, just make sure you use:



          const someLib = require('whatever)


          rather than import!






          share|improve this answer












          You need to do some reading but basically anything in a async function that returns a promise you can await like so



          module.exports.app = async (event, context, callback) => {
          try {
          const results = await SomeClass.somePromise()

          const anotherResult = await SomeOtherClass.somePromise()

          // do some stuff

          callback(null, some_valid_http_response)


          } catch (e) [

          callback(e, null) // or handle another way
          }
          }


          In short you dont await somePromise.then you just await the promise.



          If you want to save yourself a whole world of hurt switch to Node 8.10 you can use most of the latest ES6 features, just make sure you use:



          const someLib = require('whatever)


          rather than import!







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 11 at 20:49









          Mrk Fldig

          2,24341645




          2,24341645
























              up vote
              0
              down vote













              Your function is async, email.check().then(...) returns a promise which is never awaited on your side. Remove async at your lambda handler or await await email.check().then(...) the returned promise. If you remove async you have to use the callback property of lambda.






              share|improve this answer



























                up vote
                0
                down vote













                Your function is async, email.check().then(...) returns a promise which is never awaited on your side. Remove async at your lambda handler or await await email.check().then(...) the returned promise. If you remove async you have to use the callback property of lambda.






                share|improve this answer

























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Your function is async, email.check().then(...) returns a promise which is never awaited on your side. Remove async at your lambda handler or await await email.check().then(...) the returned promise. If you remove async you have to use the callback property of lambda.






                  share|improve this answer














                  Your function is async, email.check().then(...) returns a promise which is never awaited on your side. Remove async at your lambda handler or await await email.check().then(...) the returned promise. If you remove async you have to use the callback property of lambda.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 10 at 16:22

























                  answered Nov 10 at 16:05









                  smartinspereira

                  13




                  13






















                      up vote
                      0
                      down vote













                      Any method that is "thenable" is considered a Promise and will execute asynchronously. Therefore, email.check() is being invoked as a Promise and will not block code execution, which results in console.log() being invoked before you get a response. Since you're already using async/await in your lambda handler, you can just await for the response from email.check() before continuing.



                      let resp = await email.check().then(results=>{
                      console.log(results);
                      return {
                      statusCode: 200,
                      body: JSON.stringify({
                      validatedEmail: emailToValidate,
                      isValid: true,
                      }),
                      };
                      })

                      console.log( resp ); // outputs object returned from email.check()





                      share|improve this answer





















                      • Await and then doesn't really make sense buddy.
                        – Mrk Fldig
                        Nov 11 at 20:44










                      • @MrkFldig async/await returns a Promise, which means it is thenable. After all, it is simply just a wrapper around native Promises and they can be used together with no issues. Give it a try.
                        – putipong
                        Nov 12 at 19:18












                      • Simply put I'd reject any PR that used await somePromise.then() it's almost an antipattern. There are reasons for doing it, for example mysql lib returns (err, results) but you can still wrap that in a function to return the right object.
                        – Mrk Fldig
                        Nov 12 at 19:23















                      up vote
                      0
                      down vote













                      Any method that is "thenable" is considered a Promise and will execute asynchronously. Therefore, email.check() is being invoked as a Promise and will not block code execution, which results in console.log() being invoked before you get a response. Since you're already using async/await in your lambda handler, you can just await for the response from email.check() before continuing.



                      let resp = await email.check().then(results=>{
                      console.log(results);
                      return {
                      statusCode: 200,
                      body: JSON.stringify({
                      validatedEmail: emailToValidate,
                      isValid: true,
                      }),
                      };
                      })

                      console.log( resp ); // outputs object returned from email.check()





                      share|improve this answer





















                      • Await and then doesn't really make sense buddy.
                        – Mrk Fldig
                        Nov 11 at 20:44










                      • @MrkFldig async/await returns a Promise, which means it is thenable. After all, it is simply just a wrapper around native Promises and they can be used together with no issues. Give it a try.
                        – putipong
                        Nov 12 at 19:18












                      • Simply put I'd reject any PR that used await somePromise.then() it's almost an antipattern. There are reasons for doing it, for example mysql lib returns (err, results) but you can still wrap that in a function to return the right object.
                        – Mrk Fldig
                        Nov 12 at 19:23













                      up vote
                      0
                      down vote










                      up vote
                      0
                      down vote









                      Any method that is "thenable" is considered a Promise and will execute asynchronously. Therefore, email.check() is being invoked as a Promise and will not block code execution, which results in console.log() being invoked before you get a response. Since you're already using async/await in your lambda handler, you can just await for the response from email.check() before continuing.



                      let resp = await email.check().then(results=>{
                      console.log(results);
                      return {
                      statusCode: 200,
                      body: JSON.stringify({
                      validatedEmail: emailToValidate,
                      isValid: true,
                      }),
                      };
                      })

                      console.log( resp ); // outputs object returned from email.check()





                      share|improve this answer












                      Any method that is "thenable" is considered a Promise and will execute asynchronously. Therefore, email.check() is being invoked as a Promise and will not block code execution, which results in console.log() being invoked before you get a response. Since you're already using async/await in your lambda handler, you can just await for the response from email.check() before continuing.



                      let resp = await email.check().then(results=>{
                      console.log(results);
                      return {
                      statusCode: 200,
                      body: JSON.stringify({
                      validatedEmail: emailToValidate,
                      isValid: true,
                      }),
                      };
                      })

                      console.log( resp ); // outputs object returned from email.check()






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 10 at 16:51









                      putipong

                      1809




                      1809












                      • Await and then doesn't really make sense buddy.
                        – Mrk Fldig
                        Nov 11 at 20:44










                      • @MrkFldig async/await returns a Promise, which means it is thenable. After all, it is simply just a wrapper around native Promises and they can be used together with no issues. Give it a try.
                        – putipong
                        Nov 12 at 19:18












                      • Simply put I'd reject any PR that used await somePromise.then() it's almost an antipattern. There are reasons for doing it, for example mysql lib returns (err, results) but you can still wrap that in a function to return the right object.
                        – Mrk Fldig
                        Nov 12 at 19:23


















                      • Await and then doesn't really make sense buddy.
                        – Mrk Fldig
                        Nov 11 at 20:44










                      • @MrkFldig async/await returns a Promise, which means it is thenable. After all, it is simply just a wrapper around native Promises and they can be used together with no issues. Give it a try.
                        – putipong
                        Nov 12 at 19:18












                      • Simply put I'd reject any PR that used await somePromise.then() it's almost an antipattern. There are reasons for doing it, for example mysql lib returns (err, results) but you can still wrap that in a function to return the right object.
                        – Mrk Fldig
                        Nov 12 at 19:23
















                      Await and then doesn't really make sense buddy.
                      – Mrk Fldig
                      Nov 11 at 20:44




                      Await and then doesn't really make sense buddy.
                      – Mrk Fldig
                      Nov 11 at 20:44












                      @MrkFldig async/await returns a Promise, which means it is thenable. After all, it is simply just a wrapper around native Promises and they can be used together with no issues. Give it a try.
                      – putipong
                      Nov 12 at 19:18






                      @MrkFldig async/await returns a Promise, which means it is thenable. After all, it is simply just a wrapper around native Promises and they can be used together with no issues. Give it a try.
                      – putipong
                      Nov 12 at 19:18














                      Simply put I'd reject any PR that used await somePromise.then() it's almost an antipattern. There are reasons for doing it, for example mysql lib returns (err, results) but you can still wrap that in a function to return the right object.
                      – Mrk Fldig
                      Nov 12 at 19:23




                      Simply put I'd reject any PR that used await somePromise.then() it's almost an antipattern. There are reasons for doing it, for example mysql lib returns (err, results) but you can still wrap that in a function to return the right object.
                      – Mrk Fldig
                      Nov 12 at 19:23


















                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236315%2faws-lambda-promise-with-callback-issue%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      The Sandy Post

                      Danny Elfman

                      Pages that link to "Head v. Amoskeag Manufacturing Co."