I made a web application that is configured like this: Springboot (elastic beanstalk) + elasticsearch (elastic beasntalk) + postgres(aws RDS).
The connection between Springboot and aws RDS is running fine, but the problem comes with elasticsearch connection. It is a communication between dockerized containers within elastic beanstalk.
The Springboot configures elasticsearch as below.
@Value(value = "${elasticsearch.host}")
String elasticSearchHost;
public Client client() throws Exception {
Settings settings = Settings.builder()
.put("cluster.name", "elasticsearch")
.build();
return new PreBuiltTransportClient(settings)
.addTransportAddress(new TransportAddress(InetAddress.getByName(elasticSearchHost), 9300));
}
and from application.properties, I have the following value configured.
elasticsearch.host=localhost
Here is my Dockerrun.aws.json file.
{
"AWSEBDockerrunVersion": 2,
"containerDefinitions": [
{
"name": "elasticsearchmyapp",
"image": "me/elasticsearch",
"hostname": "elasticsearchmyapp",
"essential": false,
"portMappings": [
{
"hostPort": 9300,
"containerPort": 9300
}
],
"memory": 1024
},
{
"name": "myapp",
"image": "me/myapp",
"hostname": "myapp",
"essential": true,
"portMappings": [
{
"hostPort": 80,
"containerPort": 8081
}
],
"environment": [
{
"name": "ELASTICSEARCH_HOST",
"value": "elasticsearchmyapp"
}
],
"links": ["elasticsearchmyapp"],
"memory": 1024
}
]
}
Here is my logic
- I set environment variable of the Springboot container in the "environment" part.
- Because environment variable has higher priority than application.properties inside the jar, the Spring boot will refer to environment value "elasticsearchmyapp"
- Once elasticsearchmyapp is identified, the docker DNS will translate the key 'elasticsearchmyapp' to a proper URL for elasticsearch container.
But it hopeless fails every time I deploy. Saying the hostname is not identified. How can I resolve this issue?