Elasticsearch: Making EC2-Discovery Work In AWS Mumbai Region

31 / Jul / 2016 by Aakash Agarwal 2 comments

With the recently launched AWS Mumbai region, many of us might need to migrate our infrastructure there. In one such scenario, we have to setup Elasticsearch cluster on AWS EC2 instances and test it in Mumbai region.

aws-square 6764390 

While migrating Elasticsearch cluster from AWS Singapore region to Aws Mumbai region, we faced few challenges, one of them is described below:

information-icon  ChallengeThere is a plugin which enables Elasticsearch cluster to discover new nodes automatically and added them to the cluster called  “AWS Cloud Plugin. The plugin used EC2 instance tags and region to add nodes to the cluster. Once we have installed the plugin, we need to configure the “elasticsearch.yml” file. The plugin segment should look similar to this:

[js] plugin.mandatory: cloud-aws
cluster.name: mynewcluster
cloud.aws.access_key: mykey
cloud.aws.secret_key: mysecret
cloud.aws.region: us-east-1
discovery.type: ec2
discovery.ec2.tag.elasticsearch: mynewcluster[/js]

Here, we updated the cloud.aws.region to ‘ap-south-1’ (Mumbai) and restarted our Elasticsearch nodes but the nodes could not get added to the cluster and there were errors which lead us to conclude that the plugin does not support Mumbai region yet.

download The Solution: Download/Clone the plugin and get ready to make some changes. Basically, we want to update the source files and add support for Mumbai region. Once we have downloaded the plugin, we will search for the files that contain AWS Regions in them. The desired file could be searched as shown below:

[js]$ grep -rnw ./ -e ‘ap-southeast-1′[/js]

We will get all the filenames and paths that contain region names and now we know where to make changes. To be precise there are three files:

  • S3Repository.java
  • InternalAwsS3Service.java
  • AwsEc2Service.java

There is a segment of code in all these files where ‘if’ operator checks for the Region and Endpoint and it is where all the Regions and Endpoints are to be updated. Just add one more entry here for Mumbai region (ap-south-1) in all the files:

[js]else if (region.equals(‘ap-south’) || region.equals(‘ap-south-1’)) {
endpoint = ‘ec2.ap-south-1.amazonaws.com’;
}[/js]

That is it!

We can now use Jenkins to do a Maven build on the plugin’s local git repository. Once done, we need to replace the old java files with newer ones in the existing plugin on each Elasticsearch node.

On restarting Elasticsearch we will see that the new nodes are getting ‘discovered’ in the Region and are getting added to the cluster. Things work fine for Mumbai region just like any other.

See you with another write-up!

FOUND THIS USEFUL? SHARE IT

comments (2)

  1. Pradeep Reddy

    You don’t need to do all these things imo,
    You can just set this in config
    cloud:
    aws:
    ec2.endpoint: ec2.ap-south-1.amazonaws.com

    Every thing works as usual

    Reply
    1. Aakash Agarwal

      It might have worked in your case but, for the sake of portability, why not update the plugin and get rid of adding endpoint every time in the configuration file of ES.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *