static String resolveCluster(AwsConfig awsConfig, AwsMetadataApi metadataApi, Environment environment) {
        if (!isNullOrEmptyAfterTrim(awsConfig.getCluster())) {
            return awsConfig.getCluster();
        }
        if (environment.isRunningOnEcs()) {
            String cluster = metadataApi.clusterEcs();
            LOGGER.info("No ECS cluster defined, using current cluster: " + cluster);
            return cluster;
        }
        throw new InvalidConfigurationException("You must define 'cluster' property if not running inside ECS cluster");
    }
@Test
    public void resolveClusterAwsEcsMetadata() {
        // given
        String cluster = "service-name";
        AwsConfig config = AwsConfig.builder().build();
        AwsMetadataApi metadataApi = mock(AwsMetadataApi.class);
        given(metadataApi.clusterEcs()).willReturn(cluster);
        Environment environment = mock(Environment.class);
        given(environment.isRunningOnEcs()).willReturn(true);

        // when
        String result = AwsClientConfigurator.resolveCluster(config, metadataApi, environment);

        // then
        assertEquals(cluster, result);
    }