I have a Lambda configured and running on "Custom runtime on Amazon Linux 2". GraalVM is the runtime used for our application.
When Lambda tries to make a connection with OpenSearch, it always results in "java.net.SocketTimeoutException: 60,000 milliseconds timeout on connection http-outgoing-0 [ACTIVE]".
Below are some key points used in our app:
Below is RestHighLevelClient Configuration:
public class OpenSearchConfig extends AbstractElasticsearchConfiguration {
@Value("${aws.es.endpoint:defaultEndpoint}")
private String endpoint;
@Override
public RestHighLevelClient elasticsearchClient() {
return new RestHighLevelClient(RestClient.builder(HttpHost.create(endpoint)));
}
}
Note: The Lambda to OpenSearch connection was working fine when we used 'Java 11 (Corretto)' as Runtime. Since we were facing cold start issues in Lambda, we planned to use GraalVM (supported by Spring Native) for faster start up and ended up in this road block. Increasing the socket connection timeout to any limit is not helping either.
Any suggestions is much appreciated. Thanks in advance.
It seems Spring's magic isn't much compatible with GraalVM. I have modified the configurations as below and it worked fine.
@Configuration
public class OpenSearchConfig {
@Value("${aws.es.endpoint:defaultEndpoint}")
private String endpoint;
@Bean
public RestHighLevelClient elasticsearchClient() {
return new RestHighLevelClient(RestClient.builder(HttpHost.create(endpoint)));
}
}
Above I have marked RestHighLevelClient as a bean explicitly and created the ElasticsearchOperations instance as below:
private RestHighLevelClient restHighLevelClient;
private ElasticsearchOperations elasticsearchOperations;
@Autowired
public Foo(RestHighLevelClient restHighLevelClient){
this.restHighLevelClient = restHighLevelClient;
this.elasticsearchOperations = new ElasticsearchRestTemplate(this.restHighLevelClient);
}
Hope this helps someone.