Not getting any results from AWS RDS when calling from node lambda











up vote
1
down vote

favorite












I need help. I've been spinning my wheels reading stackechange all day and I've still not been able to crack this.



I've got a serverless AWS RDS DB up and running. I know it's there as I've connected to it through a tunning on an EC2 instance from my desktop (that's when I set up all the tables and data I want).



I'm now trying to connect to it and run stuff using a lambda written in node (that I'm learning).



The code I've got is this:



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

var mysql = require('mysql');
console.log('Making connection');

var con = mysql.createConnection({
host: "XXXXXXXXXXXXXXXX.amazonaws.com",
user: "xxxxx",
password: "xxxxxx",
database: "xxxxxx"
});

console.log('About to query');
con.query('SELECT * FROM players', function(error, results, fields) {
console.log('Query has run');
console.log('Row Details:', JSON.stringify(results));
context.succeed(JSON.stringify(results));
});

};


But for the life of me I can't see a result coming back. I get things like this in the cloudwatch logs:



START RequestId: a1e383cc-ee70-11e8-aac6-51ba776a3581 Version: $LATEST
2018-11-22T16:06:55.667Z a1e383cc-ee70-11e8-aac6-51ba776a3581 Making connection
2018-11-22T16:06:56.356Z a1e383cc-ee70-11e8-aac6-51ba776a3581 About to query
END RequestId: a1e383cc-ee70-11e8-aac6-51ba776a3581
REPORT RequestId: a1e383cc-ee70-11e8-aac6-51ba776a3581 Duration: 769.66 ms Billed Duration: 800 ms Memory Size: 128 MB Max Memory Used: 24 MB
START RequestId: be7f1fbd-ee70-11e8-981b-c1b991028291 Version: $LATEST
2018-11-22T16:07:43.497Z a1e383cc-ee70-11e8-aac6-51ba776a3581 Query has run
2018-11-22T16:07:43.515Z a1e383cc-ee70-11e8-aac6-51ba776a3581 Row Details: undefined
2018-11-22T16:07:43.535Z be7f1fbd-ee70-11e8-981b-c1b991028291 Making connection
2018-11-22T16:07:43.535Z be7f1fbd-ee70-11e8-981b-c1b991028291 About to query
END RequestId: be7f1fbd-ee70-11e8-981b-c1b991028291


I think a call is being made to the DB as I'm not seeing errors.



I'm calling it from the test function on the AWS Lambda console and I'm assuming I should see some JSON come back as the body of the call. However all I get is "null"



I'm guessing I'm not seeing results because of the async nature of the call. But everything I've been reading tells me the code should be working and should be waiting for the call to come back, or at least it should within the lifetime of this call.



I'm completely stuck. If anyone can give me a hint, or point me at a web page that explains how to get it work, I'd be very VERY appreciative.










share|improve this question




























    up vote
    1
    down vote

    favorite












    I need help. I've been spinning my wheels reading stackechange all day and I've still not been able to crack this.



    I've got a serverless AWS RDS DB up and running. I know it's there as I've connected to it through a tunning on an EC2 instance from my desktop (that's when I set up all the tables and data I want).



    I'm now trying to connect to it and run stuff using a lambda written in node (that I'm learning).



    The code I've got is this:



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

    var mysql = require('mysql');
    console.log('Making connection');

    var con = mysql.createConnection({
    host: "XXXXXXXXXXXXXXXX.amazonaws.com",
    user: "xxxxx",
    password: "xxxxxx",
    database: "xxxxxx"
    });

    console.log('About to query');
    con.query('SELECT * FROM players', function(error, results, fields) {
    console.log('Query has run');
    console.log('Row Details:', JSON.stringify(results));
    context.succeed(JSON.stringify(results));
    });

    };


    But for the life of me I can't see a result coming back. I get things like this in the cloudwatch logs:



    START RequestId: a1e383cc-ee70-11e8-aac6-51ba776a3581 Version: $LATEST
    2018-11-22T16:06:55.667Z a1e383cc-ee70-11e8-aac6-51ba776a3581 Making connection
    2018-11-22T16:06:56.356Z a1e383cc-ee70-11e8-aac6-51ba776a3581 About to query
    END RequestId: a1e383cc-ee70-11e8-aac6-51ba776a3581
    REPORT RequestId: a1e383cc-ee70-11e8-aac6-51ba776a3581 Duration: 769.66 ms Billed Duration: 800 ms Memory Size: 128 MB Max Memory Used: 24 MB
    START RequestId: be7f1fbd-ee70-11e8-981b-c1b991028291 Version: $LATEST
    2018-11-22T16:07:43.497Z a1e383cc-ee70-11e8-aac6-51ba776a3581 Query has run
    2018-11-22T16:07:43.515Z a1e383cc-ee70-11e8-aac6-51ba776a3581 Row Details: undefined
    2018-11-22T16:07:43.535Z be7f1fbd-ee70-11e8-981b-c1b991028291 Making connection
    2018-11-22T16:07:43.535Z be7f1fbd-ee70-11e8-981b-c1b991028291 About to query
    END RequestId: be7f1fbd-ee70-11e8-981b-c1b991028291


    I think a call is being made to the DB as I'm not seeing errors.



    I'm calling it from the test function on the AWS Lambda console and I'm assuming I should see some JSON come back as the body of the call. However all I get is "null"



    I'm guessing I'm not seeing results because of the async nature of the call. But everything I've been reading tells me the code should be working and should be waiting for the call to come back, or at least it should within the lifetime of this call.



    I'm completely stuck. If anyone can give me a hint, or point me at a web page that explains how to get it work, I'd be very VERY appreciative.










    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I need help. I've been spinning my wheels reading stackechange all day and I've still not been able to crack this.



      I've got a serverless AWS RDS DB up and running. I know it's there as I've connected to it through a tunning on an EC2 instance from my desktop (that's when I set up all the tables and data I want).



      I'm now trying to connect to it and run stuff using a lambda written in node (that I'm learning).



      The code I've got is this:



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

      var mysql = require('mysql');
      console.log('Making connection');

      var con = mysql.createConnection({
      host: "XXXXXXXXXXXXXXXX.amazonaws.com",
      user: "xxxxx",
      password: "xxxxxx",
      database: "xxxxxx"
      });

      console.log('About to query');
      con.query('SELECT * FROM players', function(error, results, fields) {
      console.log('Query has run');
      console.log('Row Details:', JSON.stringify(results));
      context.succeed(JSON.stringify(results));
      });

      };


      But for the life of me I can't see a result coming back. I get things like this in the cloudwatch logs:



      START RequestId: a1e383cc-ee70-11e8-aac6-51ba776a3581 Version: $LATEST
      2018-11-22T16:06:55.667Z a1e383cc-ee70-11e8-aac6-51ba776a3581 Making connection
      2018-11-22T16:06:56.356Z a1e383cc-ee70-11e8-aac6-51ba776a3581 About to query
      END RequestId: a1e383cc-ee70-11e8-aac6-51ba776a3581
      REPORT RequestId: a1e383cc-ee70-11e8-aac6-51ba776a3581 Duration: 769.66 ms Billed Duration: 800 ms Memory Size: 128 MB Max Memory Used: 24 MB
      START RequestId: be7f1fbd-ee70-11e8-981b-c1b991028291 Version: $LATEST
      2018-11-22T16:07:43.497Z a1e383cc-ee70-11e8-aac6-51ba776a3581 Query has run
      2018-11-22T16:07:43.515Z a1e383cc-ee70-11e8-aac6-51ba776a3581 Row Details: undefined
      2018-11-22T16:07:43.535Z be7f1fbd-ee70-11e8-981b-c1b991028291 Making connection
      2018-11-22T16:07:43.535Z be7f1fbd-ee70-11e8-981b-c1b991028291 About to query
      END RequestId: be7f1fbd-ee70-11e8-981b-c1b991028291


      I think a call is being made to the DB as I'm not seeing errors.



      I'm calling it from the test function on the AWS Lambda console and I'm assuming I should see some JSON come back as the body of the call. However all I get is "null"



      I'm guessing I'm not seeing results because of the async nature of the call. But everything I've been reading tells me the code should be working and should be waiting for the call to come back, or at least it should within the lifetime of this call.



      I'm completely stuck. If anyone can give me a hint, or point me at a web page that explains how to get it work, I'd be very VERY appreciative.










      share|improve this question















      I need help. I've been spinning my wheels reading stackechange all day and I've still not been able to crack this.



      I've got a serverless AWS RDS DB up and running. I know it's there as I've connected to it through a tunning on an EC2 instance from my desktop (that's when I set up all the tables and data I want).



      I'm now trying to connect to it and run stuff using a lambda written in node (that I'm learning).



      The code I've got is this:



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

      var mysql = require('mysql');
      console.log('Making connection');

      var con = mysql.createConnection({
      host: "XXXXXXXXXXXXXXXX.amazonaws.com",
      user: "xxxxx",
      password: "xxxxxx",
      database: "xxxxxx"
      });

      console.log('About to query');
      con.query('SELECT * FROM players', function(error, results, fields) {
      console.log('Query has run');
      console.log('Row Details:', JSON.stringify(results));
      context.succeed(JSON.stringify(results));
      });

      };


      But for the life of me I can't see a result coming back. I get things like this in the cloudwatch logs:



      START RequestId: a1e383cc-ee70-11e8-aac6-51ba776a3581 Version: $LATEST
      2018-11-22T16:06:55.667Z a1e383cc-ee70-11e8-aac6-51ba776a3581 Making connection
      2018-11-22T16:06:56.356Z a1e383cc-ee70-11e8-aac6-51ba776a3581 About to query
      END RequestId: a1e383cc-ee70-11e8-aac6-51ba776a3581
      REPORT RequestId: a1e383cc-ee70-11e8-aac6-51ba776a3581 Duration: 769.66 ms Billed Duration: 800 ms Memory Size: 128 MB Max Memory Used: 24 MB
      START RequestId: be7f1fbd-ee70-11e8-981b-c1b991028291 Version: $LATEST
      2018-11-22T16:07:43.497Z a1e383cc-ee70-11e8-aac6-51ba776a3581 Query has run
      2018-11-22T16:07:43.515Z a1e383cc-ee70-11e8-aac6-51ba776a3581 Row Details: undefined
      2018-11-22T16:07:43.535Z be7f1fbd-ee70-11e8-981b-c1b991028291 Making connection
      2018-11-22T16:07:43.535Z be7f1fbd-ee70-11e8-981b-c1b991028291 About to query
      END RequestId: be7f1fbd-ee70-11e8-981b-c1b991028291


      I think a call is being made to the DB as I'm not seeing errors.



      I'm calling it from the test function on the AWS Lambda console and I'm assuming I should see some JSON come back as the body of the call. However all I get is "null"



      I'm guessing I'm not seeing results because of the async nature of the call. But everything I've been reading tells me the code should be working and should be waiting for the call to come back, or at least it should within the lifetime of this call.



      I'm completely stuck. If anyone can give me a hint, or point me at a web page that explains how to get it work, I'd be very VERY appreciative.







      node.js amazon-web-services aws-lambda






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 at 21:19









      John Rotenstein

      66.2k774118




      66.2k774118










      asked Nov 22 at 16:18









      Spike

      185




      185
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          This is happening due to a mix between async-await and non-async await code. The smallest change you can make to fix this is to remove the async keyword before the handler function's signature, like so:



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



          If you'd still like to use async functions, you'll have to update the mysql query code using the workaround stated here: https://github.com/mysqljs/mysql/issues/1755#issuecomment-345459882






          share|improve this answer





















          • Thanks. Making that small change has meant the call now works. I guess I have further to go with understanding Async-await and database calls!
            – Spike
            Dec 3 at 9:08











          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%2f53434897%2fnot-getting-any-results-from-aws-rds-when-calling-from-node-lambda%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          This is happening due to a mix between async-await and non-async await code. The smallest change you can make to fix this is to remove the async keyword before the handler function's signature, like so:



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



          If you'd still like to use async functions, you'll have to update the mysql query code using the workaround stated here: https://github.com/mysqljs/mysql/issues/1755#issuecomment-345459882






          share|improve this answer





















          • Thanks. Making that small change has meant the call now works. I guess I have further to go with understanding Async-await and database calls!
            – Spike
            Dec 3 at 9:08















          up vote
          1
          down vote



          accepted










          This is happening due to a mix between async-await and non-async await code. The smallest change you can make to fix this is to remove the async keyword before the handler function's signature, like so:



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



          If you'd still like to use async functions, you'll have to update the mysql query code using the workaround stated here: https://github.com/mysqljs/mysql/issues/1755#issuecomment-345459882






          share|improve this answer





















          • Thanks. Making that small change has meant the call now works. I guess I have further to go with understanding Async-await and database calls!
            – Spike
            Dec 3 at 9:08













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          This is happening due to a mix between async-await and non-async await code. The smallest change you can make to fix this is to remove the async keyword before the handler function's signature, like so:



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



          If you'd still like to use async functions, you'll have to update the mysql query code using the workaround stated here: https://github.com/mysqljs/mysql/issues/1755#issuecomment-345459882






          share|improve this answer












          This is happening due to a mix between async-await and non-async await code. The smallest change you can make to fix this is to remove the async keyword before the handler function's signature, like so:



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



          If you'd still like to use async functions, you'll have to update the mysql query code using the workaround stated here: https://github.com/mysqljs/mysql/issues/1755#issuecomment-345459882







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 at 21:58









          Kunal Nagpal

          15029




          15029












          • Thanks. Making that small change has meant the call now works. I guess I have further to go with understanding Async-await and database calls!
            – Spike
            Dec 3 at 9:08


















          • Thanks. Making that small change has meant the call now works. I guess I have further to go with understanding Async-await and database calls!
            – Spike
            Dec 3 at 9:08
















          Thanks. Making that small change has meant the call now works. I guess I have further to go with understanding Async-await and database calls!
          – Spike
          Dec 3 at 9:08




          Thanks. Making that small change has meant the call now works. I guess I have further to go with understanding Async-await and database calls!
          – Spike
          Dec 3 at 9:08


















          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%2f53434897%2fnot-getting-any-results-from-aws-rds-when-calling-from-node-lambda%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

          What visual should I use to simply compare current year value vs last year in Power BI desktop

          Alexandru Averescu

          Trompette piccolo