AWS Lambda RDS connection timeout

前端 未结 8 1626
栀梦
栀梦 2020-12-14 02:10

I\'m trying to write a Lambda function using Node.js which connects to my RDS database. The database is working and accessible from my Elastic Beanstalk environment. When I

8条回答
  •  無奈伤痛
    2020-12-14 02:37

    I want to thank everyone who helped, the problem turned out to be different than I thought. The callback in the code doesn't work for some reason even though it's in AMAZON'S OWN DEFAULT SAMPLE.

    The working code looks like this:

    'use strict';
    console.log("Loading getContacts function");
    
    var AWS = require('aws-sdk');
    var mysql = require('mysql');
    
    exports.handler = (event, context) => {
    
       var connection = mysql.createConnection({
            host     : '...',
            user     : '...',
            password : '...',
            port     : 3306,
            database: 'ebdb',
            debug    :  false
        });
    
        connection.connect(function(err) {
          if (err) context.fail();
          else context.succeed('Success');
        });
    
    };
    

提交回复
热议问题