Error connecting to Opensearch service in AWS

Versions (Opensearch 2.3x ):

I’m trying to connect to an OpenSearch service running in AWS from my Java rest high level client . I have created my service without any VPC configuration and have set up a master user and password . I’m able to access the service with the curl command to create an index and also perform a bulk operation.
curl -XPOST -u ‘master_username:master_password’ ‘https://search-********/_bulk’ --data-binary ‘@loaddata.json’ -H ‘Content-Type: application/json’
Below is the code I have written to connect to the service .

final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(“master_username”, “master_password”));

        //Create a client.
        RestClientBuilder builder = RestClient.builder(new HttpHost(host))
          .setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
            @Override
            public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
              return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
                }
              });
        RestHighLevelClient client = new RestHighLevelClient(builder);
        CreateIndexRequest createIndexRequest = new CreateIndexRequest("custom-index"); 

But the above code is trying to connect to the service and throwing a connection timeout error and this particular domain url is being added to the deny List.

Caused by: java.net.ConnectException: Timeout connecting to [search-testosdomain****.us-east-1.es.amazonaws.com/52.70.58.246:80]
at org.apache.http.nio.pool.RouteSpecificPool.timeout(RouteSpecificPool.java:169)
at org.apache.http.nio.pool.AbstractNIOConnPool.requestTimeout(AbstractNIOConnPool.java:632)
at org.apache.http.nio.pool.AbstractNIOConnPool$InternalSessionRequestCallback.timeout(AbstractNIOConnPool.java:898)
at org.apache.http.impl.nio.reactor.SessionRequestImpl.timeout(SessionRequestImpl.java:198)
at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processTimeouts(DefaultConnectingIOReactor.java:213)
at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:158)
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:351)
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:221)
at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64)
at java.base/java.lang.Thread.run(Thread.java:834)
23:39:46.921 [main] DEBUG org.opensearch.client.RestClient - added [[host=http://search-testosdomain****.us-east-1.es.amazonaws.com]] to denylist
Exception in thread “main” java.net.ConnectException: Timeout connecting to [search-testosdomain****.us-east-1.es.amazonaws.com/52.70.58.246:80 ]
at org.opensearch.client.RestClient.extractAndWrapCause(RestClient.java:953)
at org.opensearch.client.RestClient.performRequest(RestClient.java:332)
at org.opensearch.client.RestClient.performRequest(RestClient.java:320)
at org.opensearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1758)
at org.opensearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1741)
at org.opensearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1705)
at org.opensearch.client.IndicesClient.create(IndicesClient.java:159)
at org.acs.opensearchagent.App.main(App.java:87)
Caused by: java.net.ConnectException: Timeout connecting to [search-testosdomain****.us-east-1.es.amazonaws.com/52.70.58.246:80 ]
at org.apache.http.nio.pool.RouteSpecificPool.timeout(RouteSpecificPool.java:169)
at org.apache.http.nio.pool.AbstractNIOConnPool.requestTimeout(AbstractNIOConnPool.java:632)
at org.apache.http.nio.pool.AbstractNIOConnPool$InternalSessionRequestCallback.timeout(AbstractNIOConnPool.java:898)
at org.apache.http.impl.nio.reactor.SessionRequestImpl.timeout(SessionRequestImpl.java:198)
at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processTimeouts(DefaultConnectingIOReactor.java:213)
at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:158)
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:351)
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:221)
at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64)
at java.base/java.lang.Thread.run(Thread.java:834)

Please let me know if there is anymore information I can provide.

Did you ever make any headway with this? I am experiencing the same…

You need to provide host, port and scheme in HttpHost constructor. If your cluster in on https port would be 443
HttpHost(, 443, https)
HttpHost(, 9200, http)