Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to connect AWS Elasticsearch from Fargate. Getting java.net.UnknownHostException

I have a Spring Boot image deployed using AWS Fargate and the Elasticsearch cluster using AWS Elasticsearch Service. Both are under same VPC and subnet. Below is the access policy of Elasticsearch:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "*"
      },
      "Action": "es:*",
      "Resource": "arn:aws:es:ap-south-1:8655488xxxxx:domain/website-qa/*"
    }
  ]
}

Security groups:
Fargate: sg-test033f776d5fbed5c0000
Elasticsearch: sg-test0e5a570cbfc389e8555

Subnet:
Fargate: subnet-test025f49153cf245a2d11,subnet-test01f19783c005010f122,subnet-test076dfbba51d92d49033
Elasticsearch: ap-south-1a: subnet-test025f49153cf245a2d11

Under the security group of elasticsearch, I have allowed the security group of Fargate for port 443 and 9200.

And below is from application.yml file:

spring:
  elasticsearch:
    rest:
      connection-timeout: 5000 #milliseconds
      read-timeout: 5000 #milliseconds
      uris: https://vpc-website-qa-xxxxxxxxxxxx.ap-south-1.es.amazonaws.com:9200

So spring boot tries to make a connection to Elasticsearch but get java.net.UnknownHostException https://vpc-website-qa-xxxxxxxxxxxx.ap-south-1.es.amazonaws.com:9200

Tried with port 443 also but didn't work. Why host is not resolved at Fargate cluster? What am I missing here?

like image 211
Puspender Avatar asked Sep 20 '25 11:09

Puspender


1 Answers

Based on the comments.

ES does not use 9200 port. Only ports 80 for http and https on port 443 are supported. From docs:

Amazon ES only accepts connections over port 80 (HTTP) or 443 (HTTPS).

Also spring-data-elasticsearch expects only the domain, so https should not be used.

Removing https and using port 443 resolved the issue.

uris: vpc-website-qa-xxxxxxxxxxxx.ap-south-1.es.amazonaws.com:443

like image 100
Marcin Avatar answered Sep 23 '25 02:09

Marcin