mmaceachran
mmaceachran

Reputation: 3358

How do I tell which ELB sent me traffic?

I have 2 clustered EC2 instances with 2 Classic ELB's one is for the DNS xxx.com and one for xxx.net. Both point to the same cluster of EC2 instances. My application needs to know whether the incoming request came from the .com or the .net URL.

The problem is that technically the ELB forwards the request, so I lose that in the header. I can get the IP address of the ELB, but Amazon will occasionally drop the ELB and give us a new one with a different IP, so it works for a while, then breaks out of nowhere.

Does Amazon offer something like a "static" ELB? I can't find anything so I assume not.

Is there any other way around this?

Upvotes: 0

Views: 93

Answers (1)

Michael - sqlbot
Michael - sqlbot

Reputation: 179314

My application needs to know whether the incoming request came from the .com or the .net URL.

Read this from the incoming HTTP Host header. If it doesn't contain one of the two expected values, throw an error (503, 421, whatever makes the most sense) and don't render anything.

The problem is that technically the ELB forwards the request, so I lose that in the header.

I don't know what this statement is intended to convey. The Host header is set by the user agent and is not modified by the ELB so your application can read it from the incoming request.

You should not be looking at the internal IP address of the ELB for anything except to log it for correlation/troubleshooting if needed.

Of course, you also don't actually need 2 Classic ELBs for this application. You can use a single classic balancer with a single certificate containing both domains, or a single Application Load Balancer with either a combo cert or two separate certs.

Upvotes: 1

Related Questions