com.distelli.aws.AWSRegionFactory Maven / Gradle / Ivy
package com.distelli.aws;
import com.amazonaws.regions.RegionUtils;
import com.amazonaws.regions.Region;
import javax.inject.Singleton;
import javax.inject.Inject;
import java.util.stream.Collectors;
import java.util.List;
import java.util.Collections;
@Singleton
public class AWSRegionFactory {
@Inject
protected AWSRegionFactory() {}
/**
* @param serviceName The service endpoint prefix which can be
* retrieved from the constant ENDPOINT_PREFIX of the specific service
* client interface.
*/
public List listRegionsForServiceName(String serviceName) {
List regions = RegionUtils.getRegionsForService(serviceName);
if ( null == regions ) return Collections.emptyList();
return regions.stream()
.map(Region::getName)
.collect(Collectors.toList());
}
}