Issue trying to access mysql through VPC in AWS-RDS through lambda

ammusk354

Earning My Ears
Joined
Feb 17, 2023
Messages
2
I have setup a VPC and an RDS database using mysql through a nodejs lambda using serverless.

The issue I am having is that I get a server internal error when testing the lambda. The lambda is using the same VPC as the RDS.

Could this be a permission issue where the lambda needs direct permission to the db instance. If so does anyone have any suggestions on what permissions would be required.

Thankyou

Here is part of the code I am using, this is to test a query and log the result to cloudwatch. It does not show up and only shows timed out.

it seems to work locally using serverless. This is just for educational purposes.
Code:
 let pool  = mysql.createPool({
        host: host.length > 0 ? host : body.host,
        port: port.length > 0 ? port : body.port,
        user: body.username,
        password: body.password,
        database: body.dbname
    });

    pool.getConnection(function(err, connection) {
        connection.query('SELECT 1 + 1 AS result', function (error, results, fields) {
            // And done with the connection.
            //connection.release();
            // Handle error after the release.
            if (error) throw error;
            else Logger.info(JSON.stringify(results));
        });
    });
      return {statusCode:200, body: JSON.stringify({})};
}
 
Last edited:












Save Up to 30% on Rooms at Walt Disney World!

Save up to 30% on rooms at select Disney Resorts Collection hotels when you stay 5 consecutive nights or longer in late summer and early fall. Plus, enjoy other savings for shorter stays.This offer is valid for stays most nights from August 1 to October 11, 2025.
CLICK HERE









DIS Facebook DIS youtube DIS Instagram DIS Pinterest

Back
Top