I am trying to access the MySQL database installed in an EC2 instance. I have written a simple AWS Lambda function in express js. The lambda function needs to access the MySQL. I am getting the below everyone when it is trying to establish the DB connection on EC2:
{
"errorType": "SequelizeConnectionError",
"errorMessage": "connect ETIMEDOUT",
"name": "SequelizeConnectionError",
"parent": {
"errorType": "Error",
"errorMessage": "connect ETIMEDOUT",
"code": "ETIMEDOUT",
"errorno": "ETIMEDOUT",
"syscall": "connect",
"fatal": true,
"stack": [
"Error: connect ETIMEDOUT",
" at Connection._handleTimeoutError (/var/task/node_modules/mysql2/lib/connection.js:173:17)",
" at ontimeout (timers.js:436:11)",
" at tryOnTimeout (timers.js:300:5)",
" at listOnTimeout (timers.js:263:5)",
" at Timer.processTimers (timers.js:223:10)"
]
},
"original": {
"errorType": "Error",
"errorMessage": "connect ETIMEDOUT",
"code": "ETIMEDOUT",
"errorno": "ETIMEDOUT",
"syscall": "connect",
"fatal": true,
"stack": [
"Error: connect ETIMEDOUT",
" at Connection._handleTimeoutError (/var/task/node_modules/mysql2/lib/connection.js:173:17)",
" at ontimeout (timers.js:436:11)",
" at tryOnTimeout (timers.js:300:5)",
" at listOnTimeout (timers.js:263:5)",
" at Timer.processTimers (timers.js:223:10)"
]
},
"stack": [
"SequelizeConnectionError: connect ETIMEDOUT",
" at Utils.Promise.tap.then.catch.err (/var/task/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:149:19)",
" at tryCatcher (/var/task/node_modules/bluebird/js/release/util.js:16:23)",
" at Promise._settlePromiseFromHandler (/var/task/node_modules/bluebird/js/release/promise.js:512:31)",
" at Promise._settlePromise (/var/task/node_modules/bluebird/js/release/promise.js:569:18)",
" at Promise._settlePromise0 (/var/task/node_modules/bluebird/js/release/promise.js:614:10)",
" at Promise._settlePromises (/var/task/node_modules/bluebird/js/release/promise.js:689:18)",
" at Async._drainQueue (/var/task/node_modules/bluebird/js/release/async.js:133:16)",
" at Async._drainQueues (/var/task/node_modules/bluebird/js/release/async.js:143:10)",
" at Immediate.Async.drainQueues [as _onImmediate] (/var/task/node_modules/bluebird/js/release/async.js:17:14)",
" at runCallback (timers.js:705:18)",
" at tryOnImmediate (timers.js:676:5)",
" at processImmediate (timers.js:658:5)"
]
}
The ec2 configurations are:-
NOTE: vpc, subnet, and security group are same in EC2 and lambda
Here is my code:- Lambda Function Code
Any help is highly appreciated!





