@Override
    public Iterable<DiscoveryNode> discoverNodes() {
        try {
            Map<String, String> addresses = awsClient.getAddresses();
            logResult(addresses);

            List<DiscoveryNode> result = new ArrayList<>();
            for (Map.Entry<String, String> entry : addresses.entrySet()) {
                for (int port = portRange.getFromPort(); port <= portRange.getToPort(); port++) {
                    Address privateAddress = new Address(entry.getKey(), port);
                    Address publicAddress = new Address(entry.getValue(), port);
                    result.add(new SimpleDiscoveryNode(privateAddress, publicAddress));
                }
            }
            return result;
        } catch (NoCredentialsException e) {
            if (!isKnownExceptionAlreadyLogged) {
                LOGGER.warning("No AWS credentials found! Starting standalone. To use Hazelcast AWS discovery, configure"
                        + " properties (access-key, secret-key) or assign the required IAM Role to your EC2 instance");
                LOGGER.finest(e);
                isKnownExceptionAlreadyLogged = true;
            }
        } catch (RestClientException e) {
            if (e.getHttpErrorCode() == HTTP_FORBIDDEN) {
                if (!isKnownExceptionAlreadyLogged) {
                    LOGGER.warning("AWS IAM Role Policy missing 'ec2:DescribeInstances' Action! Starting standalone.");
                    isKnownExceptionAlreadyLogged = true;
                }
                LOGGER.finest(e);
            } else {
                LOGGER.warning("Cannot discover nodes. Starting standalone.", e);
            }
        } catch (Exception e) {
            LOGGER.warning("Cannot discover nodes. Starting standalone.", e);
        }
        return Collections.emptyList();
    }
@Test
    public void discoverNodes() {
        // given
        String privateIp = "192.168.1.15";
        String publicIp = "38.146.24.2";
        given(awsClient.getAddresses()).willReturn(Map.of(privateIp, publicIp));

        // when
        Iterable<DiscoveryNode> nodes = awsDiscoveryStrategy.discoverNodes();

        // then
        List<DiscoveryNode> nodeList = toList(nodes);
        DiscoveryNode node1 = nodeList.get(0);
        assertEquals(privateIp, node1.getPrivateAddress().getHost());
        assertEquals(PORT1, node1.getPrivateAddress().getPort());
        assertEquals(publicIp, node1.getPublicAddress().getHost());

        DiscoveryNode node2 = nodeList.get(1);
        assertEquals(privateIp, node2.getPrivateAddress().getHost());
        assertEquals(PORT2, node2.getPrivateAddress().getPort());
        assertEquals(publicIp, node2.getPublicAddress().getHost());
    }