I am trying to connect from a web server EC2 instance to an ElasticSearch server ec2 instance. The connection is slow to nonexistent when connecting from the EC2, but very fast when connecting from a normal computer (not within AWS).
If I make the request from my laptop, it's fast:
laptop:~ jordan$ time curl -vvv search.example.org:9200
* About to connect() to search.example.org port 9200 (#0)
* Trying 1.2.3.4... connected
* Connected to search.example.org (1.2.3.4) port 9200 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8y zlib/1.2.3
> Host: search.example.org:9200
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=UTF-8
< Content-Length: 294
<
… snip …
* Connection #0 to host search.example.org left intact
* Closing connection #0
real 0m0.071s
user 0m0.004s
sys 0m0.005s
laptop:~ jordan$
From the EC2 instance, the request first tries one instance from the load balancer:
[jordan@ip-5-6-7-8 ~]$ time curl -vvv search.example.org:9200
* Rebuilt URL to: search.example.org:9200/
* Hostname was NOT found in DNS cache
* Trying 1.2.3.4...
Then it tries the other instance:
* connect to 1.2.3.4 port 9200 failed: Connection timed out
* Trying 9.10.11.12...
Before giving up entirely:
* connect to 9.10.11.12 port 9200 failed: Connection timed out
* Failed to connect to search.example.org port 9200: Connection timed out
* Closing connection 0
curl: (7) Failed to connect to search.example.org port 9200: Connection timed out
When I look at the stats for my ELB, it shows a number of "Backend Connection Errors".
Note that search.example.org
is a domain pointing to an ELB. But, if I request the instance it points to, it still encounters a connection timeout:
[jordan@ip-5-6-7-8 ~]$ time curl -vvv ec2-40-41-42-43.compute-1.amazonaws.com:9200
* Rebuilt URL to: ec2-40-41-42-43.compute-1.amazonaws.com:9200/
* Hostname was NOT found in DNS cache
* Trying 40.41.42.43...
And is still fast from a non EC2 location:
laptop:~ jordan$ time curl -vvv ec2-40-41-42-43.compute-1.amazonaws.com:9200
* About to connect() to ec2-40-41-42-43.compute-1.amazonaws.com port 9200 (#0)
* Trying 40.41.42.43... connected
* Connected to ec2-40-41-42-43.compute-1.amazonaws.com (40.41.42.43) port 9200 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8y zlib/1.2.3
> Host: ec2-40-41-42-43.compute-1.amazonaws.com:9200
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=UTF-8
< Content-Length: 294
<
… snip …
* Connection #0 to host ec2-54-85-45-128.compute-1.amazonaws.com left intact
* Closing connection #0
real 0m0.864s
user 0m0.006s
sys 0m0.011s
laptop:~ jordan$
I have nginx
running on the search
server, and accessing it from anywhere, including the other EC2 instance, is likewise fast. So it appears to be exclusively if I try to access port 9200. Note that all of the servers mentioned are in a shared security group, which includes inbound access to port 9200.
The server does appear to connect just fine if I use the Private IP address. However, I'd prefer not creating an internal load balancer if I can resolve this issue in some other manner.