Skip to content

Latest commit

 

History

History
70 lines (51 loc) · 1.96 KB

README.md

File metadata and controls

70 lines (51 loc) · 1.96 KB

aws-opensearch-localstack

AKA. aws-opensearch-localstack.

How to install AWS OpenSearch with LocalStack

Require

  • Docker Compose
  • Pip

Install Localstack awslocal. It uses awscli version 1. Reference: LocalStack awslocal limitations

pip install awscli-local[ver1]

Now download docker-compose.yml, open terminal at the root of the project and run the following command Reference: LocalStack install OpenSearch

docker-compose -f ./docker/opensearch/docker-compose.yml up -d

Now run the following command to create OpenSearch domain

awslocal opensearch create-domain --domain-name my-domain --endpoint-url http://localhost:4566

How to use in Spring Boot

Create this configuration class

@Configuration
class OpenSearchConfig {
    @Bean
    fun restHighLevelClient(): RestHighLevelClient {
        val builder = RestClient.builder(
            HttpHost.create("http://localhost.localstack.cloud:4566"))
            .setPathPrefix("/opensearch/us-east-1/my-domain")
        return RestHighLevelClient(builder)
    }
}

and this controller

@RestController
@RequestMapping("search")
class SearchController(
    val client: RestHighLevelClient,
) {
    @GetMapping()
    @ResponseStatus(HttpStatus.OK)
    fun getSearch(searchRequest: SearchRequest) = client.search(searchRequest, RequestOptions.DEFAULT)
}

Now you can GET http://localhost:8080/search

or

GET http://localhost.localstack.cloud:4566/opensearch/us-east-1/my-domain

FAQ

localstack/localstack#5723 (comment)