Skip to content

Commit 2d9ce88

Browse files
authored
Add documentation section regarding connecting to AWS OpenSearch Serverless services (#456)
Signed-off-by: Andriy Redko <[email protected]>
1 parent f894a6d commit 2d9ce88

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

README.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,86 @@ repositories {
370370
}
371371
```
372372

373+
## AWS OpenSearch Serverless support
374+
375+
For applications and services that use AWS OpenSearch Serverless offerings, the default clients will not work out of the box.
376+
377+
### Connecting AWS OpenSearch Serverless with OpenSearch RestClient
378+
379+
When using OpenSearch RestClient, the instance of `AwsRequestSigningApacheV5Interceptor` (see please [aws-request-signing-apache-interceptor](ttps://github.com/acm19/aws-request-signing-apache-interceptor) should be configured and injected into request interceptors chain. The sample configuration is provided below:
380+
381+
```
382+
@Configuration
383+
public class OpenSearchAwsClientConfiguration {
384+
@Value("${aws.os.region}")
385+
private String region = "";
386+
387+
@Bean
388+
RestClientBuilderCustomizer customizer() {
389+
return new RestClientBuilderCustomizer() {
390+
@Override
391+
public void customize(HttpAsyncClientBuilder builder) {
392+
return builder.addInterceptorLast(new AwsRequestSigningApacheV5Interceptor(
393+
"service",
394+
AwsV4HttpSigner.create(),
395+
DefaultCredentialsProvider.create(),
396+
Region.of(region)
397+
));
398+
}
399+
400+
@Override
401+
public void customize(RestClientBuilder builder) {
402+
// No additional customizations needed
403+
}
404+
};
405+
}
406+
}
407+
```
408+
409+
### Connecting AWS OpenSearch Serverless with OpenSearch Java Client
410+
411+
When using OpenSearch Java Client, the instance of the `AwsSdk2Transport` should be configured instead of the default one. The sample configuration is provided below:
412+
413+
```
414+
@Configuration
415+
public class OpenSearchAwsClientConfiguration extends OpenSearchConfiguration {
416+
@Value("${aws.os.endpoint}")
417+
private String endpoint = "";
418+
419+
@Value("${aws.os.region}")
420+
private String region = "";
421+
422+
@Value("${aws.os.username}")
423+
private String username = "";
424+
425+
@Value("${aws.os.password}")
426+
private String password = "";
427+
428+
@NonNull
429+
@Override
430+
public ClientConfiguration clientConfiguration() {
431+
return ClientConfiguration.builder()
432+
.connectedTo(endpoint)
433+
.usingSsl()
434+
.withBasicAuth(username,password)
435+
.withConnectTimeout(Duration.ofSeconds(10))
436+
.withSocketTimeout(Duration.ofSeconds(5))
437+
.build();
438+
}
439+
440+
@Override
441+
public OpenSearchTransport opensearchTransport(RestClient restClient, JsonpMapper jsonpMapper) {
442+
final SdkHttpClient httpClient = ApacheHttpClient.builder().build();
443+
return new AwsSdk2Transport(
444+
httpClient,
445+
endpoint,
446+
"es" // signing service name, use "aoss" for OpenSearch Serverless
447+
region,
448+
AwsSdk2TransportOptions.builder().build());
449+
}
450+
}
451+
```
452+
373453
## Reporting Issues
374454

375455
Spring Data OpenSearch uses GitHub as issue tracking system to record bugs and feature requests.

0 commit comments

Comments
 (0)