Node.js Elastic Beanstalk TIMEDOUT ErrorPosted on
I got an error when deploying my Node.js app into AWS Elastic Beanstalk (EB). The error said
Error: connect ETIMEDOUT at errnoException (net.js:901:11) at Object.afterConnect [as oncomplete] (net.js:892:19) -------------------- at Protocol._enqueue (/var/app/current/node_modules/mysql/lib/protocol/Protocol.js:110:26) at Protocol.handshake (/var/app/current/node_modules/mysql/lib/protocol/Protocol.js:42:41)
My Node.js app using node-mysql module to access database. You can see “mysql” in the error statement. Seeing from errors, this must be related with database. I use Amazon Relational Database Service (RDS) and my node.js app is configured to connect with it.
After exploring this error, I know why it is occurred. It is caused by security group of my EB instance which is not allowed to connect to DB instance in RDS. To overcome this problem, follow these steps:
1) Go to app in Elastic Beanstalk
2) Choose the environment
3) Choose configuration then choose instance
4) Check its EC2 security groups
5) Go to RDS menu
6) Choose DB Instance
7) Add the security group you found at step 4 to DB Instance
8) Click Authorize
I can conclude that everytime you create new EB instance you need to add its security group to DB instance in RDS so your Node.js app can connect to it. Hope this article helps you.