Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restrict EC2 security group to Elastic Beanstalk instances

I have my MongoDB deployed in an EC2 instance, nice and steady. I will (hopefully) have my Elastic Beanstalk load-balanced Web App launched soon using Docker. However, I feel like my Database is too sensitive to dockerize or beastalk-ize, so I wanna keep it in a plain EC2 instance.

Excuse my horrible diagram

My issue is with regard to the security groups. How can I create a security group that will only accept MongoDB traffic (port 27017) from the Elastic Beanstalk? Since EC2 instances will get created and destroyed arbitrarily, maybe I can get the least-common subnet of those?

enter image description here

like image 955
rausted Avatar asked Mar 11 '23 11:03

rausted


1 Answers

When you create your Elastic Beanstalk application, you will choose a security group to assign to it's EC2 instances.

For your MongoDB security group, allow traffic on port 27017 for the EB EC2's security group. If done this way, then only EC2 instances using that security group can access the MongoDB instance.

Note, when accessing your MongoDB instance from your EB app's EC2 instance, makes sure you use the private IP address of the MongoDB instance, and not the public IP address. If you use the public IP address, then AWS doesn't recognize the connection as originating from the EB security group and will deny the connection.

like image 135
Matt Houser Avatar answered Apr 06 '23 09:04

Matt Houser