title: Spring Cloud Eureka Cluster Setup in AWS using DNS based Elastic Network Interface (ENI)
body: <p>I am trying to setup eureka cluster in us-east-1 region. There are 2 availability zones (zone b &amp; d), and running an instance of eureka server on each zone. We setup DNS text record which refers to ENI of servers in each zone.</p>
  
  <p>Spring boot version - 2.0.5.RELEASE</p>
  
  <p>Following are more information about environment:</p>
  
  <p><strong>Zone b:</strong></p>
  
  <pre><code>IP Address - XX.XXX.XXX.250
  Hostname - ip-XX-XXX-XXX-250.ec2.internal
  ENI IP Address - XX.XXX.XXX.133
  ENI hostname - ip-XX-XXX-XXX-133.ec2.internal
  </code></pre>
  
  <p><strong>Zone d:</strong></p>
  
  <pre><code>IP Address - XX.XXX.XXX.176
  Hostname - ip-XX-XXX-XXX-176.ec2.internal
  ENI IP Address - XX.XXX.XXX.161
  ENI hostname - ip-XX-XXX-XXX-161.ec2.internal
  </code></pre>
  
  <p><strong>DNS Configuration:</strong></p>
  
  <pre><code>dig -t txt txt.us-east-1.dev-aws.XXXXX.com
  ;; ANSWER SECTION:
  txt.us-east-1.dev-aws.XXXXX.com. 300 IN TXT "us-east-1b.dev-aws.XXXXX.com"
  txt.us-east-1.dev-aws.XXXXX.com. 300 IN TXT "us-east-1d.dev-aws.XXXXX.com"
  
  nslookup -q=txt txt.us-east-1b.dev-aws.XXXXX.com
  Non-authoritative answer:
  txt.us-east-1b.dev-aws.XXXXX.com    text = "ip-XX-XXX-XXX-133.ec2.internal"
  
  nslookup -q=txt txt.us-east-1d.dev-aws.XXXXX.com
  Non-authoritative answer:
  txt.us-east-1d.dev-aws.XXXXX.com    text = "ip-XX-XXX-XXX-161.ec2.internal"
  </code></pre>
  
  <p><strong>application.properties</strong></p>
  
  <pre><code>server.port=8761
  eureka.client.fetch-registry=true
  eureka.client.eureka-server-u-r-l-context=eureka
  eureka.client.region=us-east-1
  eureka.client.eureka-server-port=8761
  eureka.client.use-dns-for-fetching-service-urls=true
  eureka.client.eureka-server-d-n-s-name=dev-aws.XXXXX.com
  eureka.client.register-with-eureka=true
  eureka.server.binding-strategy=ENI
  eureka.datacenter=cloud
  eureka.environment=AWS-DEV
  </code></pre>
  
  <p><strong>SpringEurekaServerAwsApplication.java</strong></p>
  
  <pre><code>import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
  
  @SpringBootApplication
  @EnableEurekaServer
  public class SpringEurekaServerAwsApplication {
      public static void main(String[] args) {
          SpringApplication.run(SpringEurekaServerAwsApplication.class, args);
      }
  
      @Bean
      public EurekaInstanceConfigBean eurekaInstanceConfig(InetUtils inetUtils) {
          EurekaInstanceConfigBean eurekaInstanceConfigBean = new EurekaInstanceConfigBean(inetUtils);
          AmazonInfo info = AmazonInfo.Builder.newBuilder().autoBuild("eureka");
          eurekaInstanceConfigBean.setDataCenterInfo(info);
          eurekaInstanceConfigBean.setHostname(info.get(AmazonInfo.MetaDataKey.localHostname));
          eurekaInstanceConfigBean.setIpAddress(info.get(AmazonInfo.MetaDataKey.localIpv4));
          return eurekaInstanceConfigBean;
      }   
  }
  </code></pre>
  
  <p>I am able to see all instances currently registered in eureka on both instances but available replica is always blank. It looks like an issue in spring cloud eureka server. Could someone help to look into this issue?</p>
  
  <p>Following are the screenshot of eureka dashboard:</p>
  
  <p><strong>Zone b</strong>
  <a href="https://i.stack.imgur.com/vN3Mm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vN3Mm.jpg" alt="enter image description here"></a></p>
  
  <p><strong>Zone d</strong>
  <a href="https://i.stack.imgur.com/U9VEB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/U9VEB.jpg" alt="enter image description here"></a></p>
  
  <p>Added in <a href="https://github.com/spring-cloud/spring-cloud-netflix/issues/3229" rel="nofollow noreferrer">github</a></p>
  
  <p>@RyanBaxter Ryan - I am able to see replicated instances in "Instances currently registered with Eureka", but "available-replicas" is blank. Moreover, it is taking time (not consistent, around 30-50 mins) to reflect registered instance in replicas. I can also following in eureka server logs, looks like some configuration is incorrect, but not able to find it.</p>
  
  <pre><code>2018-10-12 15:46:52.624  INFO 26564 --- [Eureka-PeerNodesUpdater] c.n.eureka.cluster.PeerEurekaNodes       : Removing no longer available peer nodes [http://ip-XX-XXX-XXX-161.ec2.internal:8761/eureka/]
  2018-10-12 15:46:52.624  INFO 26564 --- [Eureka-PeerNodesUpdater] c.n.eureka.cluster.PeerEurekaNodes       : Adding new peer nodes [http://ip-XX-XXX-XXX-133.ec2.internal:8761/eureka/]
  
  2018-10-12 16:16:52.730  INFO 26564 --- [Eureka-PeerNodesUpdater] c.n.eureka.cluster.PeerEurekaNodes       : Removing no longer available peer nodes [http://ip-XX-XXX-XXX-133.ec2.internal:8761/eureka/]
  2018-10-12 16:16:52.731  INFO 26564 --- [Eureka-PeerNodesUpdater] c.n.eureka.cluster.PeerEurekaNodes       : Adding new peer nodes [http://ip-XX-XXX-XXX-161.ec2.internal:8761/eureka/]
  </code></pre>
  
  <p>One more issue - Eureka is not unbinding ENI during shutdown due to below exception:</p>
  
  <pre><code>2018-10-17 14:26:34.756  INFO 2389 --- [Thread-16] com.netflix.discovery.DiscoveryClient    : Shutting down DiscoveryClient ...
  2018-10-17 14:26:34.758  WARN 2389 --- [Thread-16] .s.c.a.CommonAnnotationBeanPostProcessor : Invocation of destroy method failed on bean with name 'scopedTarget.eurekaClient': org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'eurekaInstanceConfig': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
  </code></pre>