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
    public void credentialsAccessKey() {
        // given
        AwsConfig awsConfig = AwsConfig.builder()
            .setAccessKey(ACCESS_KEY)
            .setSecretKey(SECRET_KEY)
            .build();
        AwsCredentialsProvider credentialsProvider = new AwsCredentialsProvider(awsConfig, awsMetadataApi, environment);

        // when
        AwsCredentials credentials = credentialsProvider.credentials();

        // then
        assertEquals(ACCESS_KEY, credentials.getAccessKey());
        assertEquals(SECRET_KEY, credentials.getSecretKey());
        assertNull(credentials.getToken());
    }