AwsCredentials credentials() {
        if (!StringUtil.isNullOrEmptyAfterTrim(awsConfig.getAccessKey())) {
            return AwsCredentials.builder()
                .setAccessKey(awsConfig.getAccessKey())
                .setSecretKey(awsConfig.getSecretKey())
                .build();
        }
        if (!StringUtil.isNullOrEmptyAfterTrim(ec2IamRole)) {
            return fetchCredentialsFromEc2();
        }
        if (environment.isRunningOnEcs()) {
            return fetchCredentialsFromEcs();
        }
        throw new NoCredentialsException();
    }
@Test(expected = InvalidConfigurationException.class)
    public void credentialsEcsException() {
        // given
        AwsConfig awsConfig = AwsConfig.builder().build();
        given(awsMetadataApi.credentialsEcs()).willThrow(new RuntimeException("Error fetching credentials"));
        given(environment.isRunningOnEcs()).willReturn(true);
        AwsCredentialsProvider credentialsProvider = new AwsCredentialsProvider(awsConfig, awsMetadataApi, environment);

        // when
        credentialsProvider.credentials();

        // then
        // throws exception
    }