title: IMDSv2 support for AWS EC2 Auto Discovery
body: <p>I am facing issue with EC2 Auto Discovery because of IMDSv2. Its a a session-oriented method. Here we need to generate the token before any metadata API is being called.</p>
  <p>checked the latest BETA Version for hazelcast as well but this has not yet implemented.</p>
  <p>I tried to send most of the config through Java Code but still for getting instanceMetaData, Availability zone is getting triggered.</p>
  <p>Following is my Config</p>
  <pre><code> Using AWS discovery plugin with configuration: AwsConfig{accessKey='***', secretKey='***', iamRole='cicd', region='ap-southeast-1', hostHeader='null', securityGroupName='null', tags='[(key=Name, value=bac-p-o-feature-store-read)]', hzPort=5701-5701, cluster='null', family='null', serviceName='null', connectionTimeoutSeconds=10, connectionRetries=3, readTimeoutSeconds=10}
  </code></pre>
  <p>Below is the Stack Trace:</p>
  <pre><code>2022-09-13 12:36:21.053  WARN 3829 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hazelcastController': Invocation of init method failed; nested exception is com.hazelcast.aws.RestClientException: Failure executing: GET at: http://169.254.169.254/latest/meta-data/placement/availability-zone/. Message: null. HTTP Error Code: 401
  2022-09-13 12:36:21.056  INFO 3829 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
  2022-09-13 12:36:21.066  INFO 3829 --- [           main] ConditionEvaluationReportLoggingListener :
  
  Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
  2022-09-13 12:36:21.092 ERROR 3829 --- [           main] o.s.boot.SpringApplication               : Application run failed
  
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hazelcastController': Invocation of init method failed; nested exception is com.hazelcast.aws.RestClientException: Failure executing: GET at: http://169.254.169.254/latest/meta-data/placement/availability-zone/. Message: null. HTTP Error Code: 401
      at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:160) ~[spring-beans-5.3.22.jar!/:5.3.22]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:440) ~[spring-beans-5.3.22.jar!/:5.3.22]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796) ~[spring-beans-5.3.22.jar!/:5.3.22]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.22.jar!/:5.3.22]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.22.jar!/:5.3.22]
      at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.22.jar!/:5.3.22]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.22.jar!/:5.3.22]
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.22.jar!/:5.3.22]
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.22.jar!/:5.3.22]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955) ~[spring-beans-5.3.22.jar!/:5.3.22]
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.22.jar!/:5.3.22]
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.22.jar!/:5.3.22]
      at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.3.jar!/:2.7.3]
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) [spring-boot-2.7.3.jar!/:2.7.3]
      at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) [spring-boot-2.7.3.jar!/:2.7.3]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) [spring-boot-2.7.3.jar!/:2.7.3]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) [spring-boot-2.7.3.jar!/:2.7.3]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) [spring-boot-2.7.3.jar!/:2.7.3]
      at com.meesho.ml.hazelcastlocalsetup.HazelcastLocalSetupApplication.main(HazelcastLocalSetupApplication.java:10) [classes!/:0.0.1-SNAPSHOT]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_342]
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_342]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_342]
      at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_342]
      at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) [hazelcast-local-setup-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
      at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) [hazelcast-local-setup-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
      at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) [hazelcast-local-setup-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
      at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) [hazelcast-local-setup-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
  Caused by: com.hazelcast.aws.RestClientException: Failure executing: GET at: http://169.254.169.254/latest/meta-data/placement/availability-zone/. Message: null. HTTP Error Code: 401
      at com.hazelcast.aws.RestClient.checkResponseCode(RestClient.java:148) ~[hazelcast-all-5.0-BETA-1.jar!/:5.0-BETA-1]
      at com.hazelcast.aws.RestClient.call(RestClient.java:126) ~[hazelcast-all-5.0-BETA-1.jar!/:5.0-BETA-1]
      at com.hazelcast.aws.RestClient.lambda$callWithRetries$0(RestClient.java:99) ~[hazelcast-all-5.0-BETA-1.jar!/:5.0-BETA-1]
      at com.hazelcast.aws.RetryUtils.retry(RetryUtils.java:51) ~[hazelcast-all-5.0-BETA-1.jar!/:5.0-BETA-1]
      at com.hazelcast.aws.RestClient.callWithRetries(RestClient.java:99) ~[hazelcast-all-5.0-BETA-1.jar!/:5.0-BETA-1]
      at com.hazelcast.aws.RestClient.get(RestClient.java:91) ~[hazelcast-all-5.0-BETA-1.jar!/:5.0-BETA-1]
      at com.hazelcast.aws.AwsMetadataApi.availabilityZoneEc2(AwsMetadataApi.java:71) ~[hazelcast-all-5.0-BETA-1.jar!/:5.0-BETA-1]
      at com.hazelcast.aws.AwsEc2Client.getAvailabilityZone(AwsEc2Client.java:40) ~[hazelcast-all-5.0-BETA-1.jar!/:5.0-BETA-1]
      at com.hazelcast.aws.AwsDiscoveryStrategy.discoverLocalMetadata(AwsDiscoveryStrategy.java:135) ~[hazelcast-all-5.0-BETA-1.jar!/:5.0-BETA-1]
      at com.hazelcast.spi.discovery.impl.DefaultDiscoveryService.discoverLocalMetadata(DefaultDiscoveryService.java:89) ~[hazelcast-all-5.0-BETA-1.jar!/:5.0-BETA-1]
      at com.hazelcast.instance.impl.Node.mergeEnvironmentProvidedMemberMetadata(Node.java:610) ~[hazelcast-all-5.0-BETA-1.jar!/:5.0-BETA-1]
      at com.hazelcast.instance.impl.Node.start(Node.java:458) ~[hazelcast-all-5.0-BETA-1.jar!/:5.0-BETA-1]
      at com.hazelcast.instance.impl.HazelcastInstanceImpl.&lt;init&gt;(HazelcastInstanceImpl.java:124) ~[hazelcast-all-5.0-BETA-1.jar!/:5.0-BETA-1]
      at com.hazelcast.instance.impl.HazelcastInstanceFactory.constructHazelcastInstance(HazelcastInstanceFactory.java:211) ~[hazelcast-all-5.0-BETA-1.jar!/:5.0-BETA-1]
      at com.hazelcast.instance.impl.HazelcastInstanceFactory.getOrCreateHazelcastInstance(HazelcastInstanceFactory.java:108) ~[hazelcast-all-5.0-BETA-1.jar!/:5.0-BETA-1]
      at com.hazelcast.core.Hazelcast.getOrCreateHazelcastInstance(Hazelcast.java:169) ~[hazelcast-all-5.0-BETA-1.jar!/:5.0-BETA-1]
      at com.meesho.ml.hazelcastlocalsetup.controller.HazelcastController.init(HazelcastController.java:58) ~[classes!/:0.0.1-SNAPSHOT]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_342]
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_342]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_342]
      at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_342]
      at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:389) ~[spring-beans-5.3.22.jar!/:5.3.22]
      at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:333) ~[spring-beans-5.3.22.jar!/:5.3.22]
      at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:157) ~[spring-beans-5.3.22.jar!/:5.3.22]
      ... 26 common frames omitted
  </code></pre>