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.
node.js amazon-web-services aws-lambda
add a comment |
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.
node.js amazon-web-services aws-lambda
add a comment |
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.
node.js amazon-web-services aws-lambda
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
node.js amazon-web-services aws-lambda
edited Nov 22 at 21:19
John Rotenstein
66.2k774118
66.2k774118
asked Nov 22 at 16:18
Spike
185
185
add a comment |
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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