AWS EC2 Auto Scaling Groups, RDS, Route 53 and Constantly changing IP addresses

amazon ec2amazon-rdsamazon-route53amazon-web-servicesautoscaling

I setup an auto scaling group on EC2 along with an RDS Postgres instance. I am not using ELB. Maybe I should be…

The challenge is that every time a new EC2 instance is created it assigns a unique public IP address. This means that a new inbound rule needs to be applied to the security group for RDS that allows this new EC2 instance to connect to RDS via port 5432 (postgresql).

I also run into a Route 53 issue since the new ip address needs to be added to the DNS "A Record" in order to properly resolve the url.

Is there a way to setup AWS to do this for me, or do I need to write some python code using boto?

Best Answer

This means that a new inbound rule needs to be applied to the security group for RDS that allows this new EC2 instance to connect to RDS via port 5432 (postgresql).

Rather than using public IPs for your security group rules, I suggest using private IPs. Run both EC2 and RDS in the same VPC, then allow the entire VPC subnet IP range containing your EC2 instances in your security group rules for RDS.

I also run into a Route 53 issue since the new ip address needs to be added to the DNS "A Record" in order to properly resolve the url.

You basically have 3 options:

  1. Use ELB
  2. Write a setup script that runs on each instance and updates the DNS automatically
  3. Use OpsWorks which allows you to make a HAProxy instance with an EIP, then automatically adds new application server instances to that HAProxy instance when they start
Related Topic