Using this code snippet, I can get a region list in my AWS account, but why do I have to enter a region name to get region list (In this case "us-east-1").
AWSCredentials credentials = new BasicAWSCredentials("accessKey", "secretKey");
AWSCredentialsProvider credentialsProvider=new AWSStaticCredentialsProvider(credentials);
AmazonEC2 ec2 = AmazonEC2ClientBuilder.standard()
.withCredentials(credentialsProvider)
.withRegion("us-east-1")
.build();
DescribeRegionsResult regions_response = ec2.describeRegions();
for(Region region : regions_response.getRegions()) {
System.out.println(region.getRegionName());
}
}
From AWS service endpoints - AWS General Reference:
Your code is calling the Amazon EC2 service. To do so, the API call must be sent to an EC2 endpoint in a Region. The EC2 service will respond to requests made to that endpoint.
The fact that your particular API call is asking for a list of Regions does not make it any different to other API calls, such as requests to Stop or Start instances. The request must still be sent to an API endpoint. All regions will respond with the same list of regions.
So, the simple answer is: The Region identifier helps determine where to send the request.