Providing Static IP in front of AWS ELB (Elastic Load Balancer)

February 24, 2016

So, certain situations can arise (often times security) where you will need static IP addresses in front of your ELBs. Not everyone needs this but a rising number of people are starting to, and I will show you how. The only use case I’ve ran into this is on AWS, not anywhere else. But if it works it works.

Currently there are only two solutions I have found: HAProxy 1.6, and Nginx (goes back to versions farther than 3 years ago). Here’s how

In Nginx:

There is a configuration value called “resolver”, here is an example. It can be used in your  http, server, or location  context.

An in use example:

This will force Nginx to update the DNS for example.com every 10s. In applications I have done we set this to 2s, because it works better for the amount of scaling up and down we do. Since doing this we haven’t seen any failures related to DNS resolution of ELBs.

As a side not, putting it in the http context does have some issues and you may end up with stale DNS data, even with valid=10s, etc.

 

Leave a Reply