EC2 host discovery supports a number of settings. Some settings are sensitive and must be stored in the elasticsearch keystore. For example, to use explicit AWS access keys:

bin/elasticsearch-keystore add discovery.ec2.access_key
bin/elasticsearch-keystore add discovery.ec2.secret_key

The following are the available discovery settings. All should be prefixed with discovery.ec2.. Those that must be stored in the keystore are marked as Secure.

An ec2 access key. The secret_key setting must also be specified. (Secure)
An ec2 secret key. The access_key setting must also be specified. (Secure)
An ec2 session token. The access_key and secret_key settings must also be specified. (Secure)
The ec2 service endpoint to connect to. This will be automatically figured out by the ec2 client based on the instance location, but can be specified explicitly. See
The protocol to use to connect to ec2. Valid values are either http or https. Defaults to https.
The host name of a proxy to connect to ec2 through.
The port of a proxy to connect to ec2 through.
The username to connect to the with. (Secure)
The password to connect to the with. (Secure)
The socket timeout for connecting to ec2. The value should specify the unit. For example, a value of 5s specifies a 5 second timeout. The default value is 50 seconds.
Either a comma separated list or array based list of (security) groups. Only instances with the provided security groups will be used in the cluster discovery. (NOTE: You could provide either group NAME or group ID.)

The type of host type to use to communicate with other instances. Can be one of private_ip, public_ip, private_dns, public_dns or tag:TAGNAME where TAGNAME refers to a name of a tag configured for all EC2 instances. Instances which don’t have this tag set will be ignored by the discovery process.

For example if you defined a tag my-elasticsearch-host in ec2 and set it to, then setting host_type: tag:my-elasticsearch-host will tell Discovery Ec2 plugin to read the host name from the my-elasticsearch-host tag. In this case, it will be resolved to Read more about EC2 Tags.

Defaults to private_ip.

Either a comma separated list or array based list of availability zones. Only instances within the provided availability zones will be used in the cluster discovery.
If set to false, will require all security groups to be present for the instance to be used for the discovery. Defaults to true.
How long the list of hosts is cached to prevent further requests to the AWS API. Defaults to 10s.

All secure settings of this plugin are reloadable. After you reload the settings, an aws sdk client with the latest settings from the keystore will be used.

Binding the network host

It’s important to define as by default it’s bound to localhost.

You can use core network host settings or ec2 specific host settings:

EC2 Network Hostedit

When the discovery-ec2 plugin is installed, the following are also allowed as valid network host settings:

EC2 Host Value Description


The private IP address (ipv4) of the machine.


The private host of the machine.


The public IP address (ipv4) of the machine.


The public host of the machine.


equivalent to _ec2:privateIpv4_.


equivalent to _ec2:publicIpv4_.


equivalent to _ec2:privateIpv4_.

Recommended EC2 Permissionsedit

EC2 discovery requires making a call to the EC2 service. You’ll want to setup an IAM policy to allow this. You can create a custom policy via the IAM Management Console. It should look similar to this.

  "Statement": [
      "Action": [
      "Effect": "Allow",
      "Resource": [
  "Version": "2012-10-17"

Filtering by Tagsedit

The ec2 discovery can also filter machines to include in the cluster based on tags (and not just groups). The settings to use include the discovery.ec2.tag. prefix. For example, setting discovery.ec2.tag.stage to dev will only filter instances with a tag key set to stage, and a value of dev. Several tags set will require all of those tags to be set for the instance to be included.

One practical use for tag filtering is when an ec2 cluster contains many nodes that are not running Elasticsearch. In this case (particularly with high discovery.zen.ping_timeout values) there is a risk that a new node’s discovery phase will end before it has found the cluster (which will result in it declaring itself master of a new cluster with the same name - highly undesirable). Tagging Elasticsearch ec2 nodes and then filtering by that tag will resolve this issue.

Automatic Node Attributesedit

Though not dependent on actually using ec2 as discovery (but still requires the discovery-ec2 plugin installed), the plugin can automatically add node attributes relating to ec2. In the future this may support other attributes, but this will currently only add an aws_availability_zone node attribute, which is the availability zone of the current node. Attributes can be used to isolate primary and replica shards across availability zones by using the Allocation Awareness feature.

In order to enable it, set cloud.node.auto_attributes to true in the settings. For example:

cloud.node.auto_attributes: true

cluster.routing.allocation.awareness.attributes: aws_availability_zone