1

my RDS mysql public database instance can be connected from mysql clients. But when i trying the same in AWS Lambda it won't work. my code is given below.

console.log('Loading function');
var doc = require('dynamodb-doc');
var dynamo = new doc.DynamoDB();
var mysql = require('mysql');
exports.handler = function(event, context) {
//console.log('Received event:', JSON.stringify(event, null, 2));  
var operation = event.operation;
delete event.operation;
switch (operation) {
case 'create':
var conn = mysql.createConnection({
host      :  'lamdatest.********.rds.amazonaws.com' ,  // RDS endpoint 
user      :  'user' ,  // MySQL username 
password  :  'password' ,  // MySQL password 
database  :  'rdslamda' 
});
conn.connect();
console.log("connecting...");
conn.query ( 'INSERT INTO login (name,password) VALUES("use6","password6")' ,     function(err, info){
        console.log("insert: "+info.msg+" /err: "+err);
    });
console.log("insert values in to database");
break;
case 'read':
dynamo.getItem(event, context.done());
break;

default:
context.fail(new Error('Unrecognized operation "' + operation + '"'));

}
context.succeed();
};  

When i checked out the mysqli-error.log file in the RDS it's shows an error given below.

2015-08-09 19:36:24 2630 [Warning] IP address '117.253.192.122' could not be resolved:  
Temporary failure in name resolution  

----------------------- END OF LOG ----------------------
ARUNBALAN NV
  • 1,634
  • 4
  • 17
  • 39
  • what does the security group look like for this database? and to confirm, the quoted `mysqli-error.log` is from the Lambda service? – tedder42 Aug 10 '15 at 00:32
  • The security group is default. the quoted `mysqli-error.log` is from RDS instance console.it has created when i invoked the lambda function. – ARUNBALAN NV Aug 10 '15 at 04:54
  • the description for the security group is:default VPC security group – ARUNBALAN NV Aug 10 '15 at 05:04
  • What are the *contents* of the security group? Also, that IP does not belong to AWS; Lambda does not run on that IP. – tedder42 Aug 10 '15 at 05:07
  • Sorry the security group details are here. `Type: MYSQL/Aurora, Protocol:TCP, PortRange:3306, Source: 0.0.0.0/0.` – ARUNBALAN NV Aug 10 '15 at 05:52
  • They only recently added VPC support for Lambda. If that was part of the problem, maybe it's better now. – Jay Carlton Nov 12 '15 at 21:31
  • see this https://stackoverflow.com/questions/31809890/can-aws-lambda-connect-to-rds-mysql-database-and-update-the-database – ARUNBALAN NV Feb 12 '18 at 08:56

0 Answers0