0

How can I get list of all regions to show to user to choose from. basically I want to show a dropdown with all regions possible.

This is for S3 bucket configuration (not sure if ec2 describe region would work?).

All it should be dynamic and not tried to and SDK so that if AWS creates a new region user should be able to select it. (So don't want to use Regions enum)

I am using aws java sdk.

Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
  • If you don't use the Regions enum, and get the list from elsewhere, wouldn't that imply that you would be allowing your user to select a region that the deployed version of your code doesn't actually support? I don't work with the Java SDK but that seems problematic, unless the SDK has a way of correctly handling new regions without updating the deployed library version. – Michael - sqlbot Dec 08 '17 at 13:32

1 Answers1

0

I used ec2client with describeRegions api to get eligible regions -

    BasicAWSCredentials credentials = new BasicAWSCredentials(awsAcessKeyId, awsSecretKey);

    AmazonEC2 ec2Client = AmazonEC2ClientBuilder.standard()
            .withCredentials(new AWSStaticCredentialsProvider(credentials)).build();
    DescribeRegionsResult describeRegionsResult = ec2Client.describeRegions();
    for(com.amazonaws.services.ec2.model.Region region : describeRegionsResult.getRegions()) {
        System.out.println(region.getRegionName());
    }
Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289