Search code examples
javaamazon-web-servicesamazon-route53

Which region endpoint should AWS Java SDK v2 be using for Route 53?


On Windows 10 I'm using the AWS Java SDK v2 (software.amazon.awssdk:route53:2.8.3) and I'm trying to merely connect and list all my Route 53 hosted zones. I have us-west-1 specified in my user configuration (in my .aws/config file) as the default region.

I create a Route53Client using the following:

Route53Client route53Client = Route53Client.builder().build();

Note that I don't indicate a region, because in the online documentation it says:

When you submit requests using the AWS CLI or SDKs, either leave the Region and endpoint unspecified, or specify us-east-1 as the Region.

I then try to list hosted zones using something like this:

Set<HostedZone> hostedZones = client.listHostedZonesPaginator().stream()
  .flatMap(response -> response.hostedZones().stream())
  .collect(Collectors.toSet());

In the logs I see a debug message like this:

[DEBUG] Unable to load region from software.amazon.awssdk.regions.providers.SystemSettingsRegionProvider@...:Unable to load region from system settings. Region must be specified either via environment variable (AWS_REGION) or system property (aws.region).

Then it throws a java.net.UnknownHostException for route53.us-west-1.amazonaws.com.

Granted I am on a spotty Internet connection right now. Is that the correct endpoint? If it is, the why isn't that endpoint listed at https://docs.aws.amazon.com/general/latest/gr/rande.html ? If it isn't, why is it trying to connect to a us-west1 endpoint, if I'm following the online documentation (as I quoted above), which indicates that a region need not be indicated? Or is the problem simply my Internet connection and spotty DNS lookup at the moment?


Solution

  • The AWS SDK development team decided to require Route53 requests to explicitly indicate the Region.AWS_GLOBAL or requests would not work, as someone noted in Issue #456 for the SDK:

    To access Route53 you would currently need to specify the AWS_GLOBAL region. This was done to prevent customers from using global services and not realizing that for this service your calls are likely not staying in region and could potentially be spanning the globe.

    Unfortunately Amazon didn't bother documenting this in the SDK (that I could find), and didn't provide a helpful error message, instead assuming developers would somehow guess the problem when the SDK tried to access an endpoint that did not exist even though the SDK was being used according to the API and according to the online documentation.

    In short the Route53 client must be created like this:

    route53Client = Route53Client.builder().region(Region.AWS_GLOBAL).build();