title: java.lang.IllegalArgumentException: hostname cannot be null when trying to obtain AWS ECR Authentication Token
body: <p>I am trying to obtain ECR authorisation token from AWS using aws-java-sdk version 1.11.339. I have created a class to do so as below:</p>
  
  <pre><code>public class ECRTokenGetter {
      private static final Logger LOGGER = LoggerFactory.getLogger(ECRTokenGetter.class);
      private static final int SINGLE_ELEMENT_INDEX = 0;
  
  
      public static String getEcrAuthorisationToken(Credentials creds, String awsRegion, String registryId) {
          LOGGER.debug("Obtaining temporary authorisation credentials from AWS ECR");
  
          AmazonECR ecrClient = AmazonECRClientBuilder.standard()
                  .withRegion(awsRegion)
                  .withCredentials(new AWSStaticCredentialsProvider(new BasicSessionCredentials(
                          creds.getAccessKeyId(),
                          creds.getSecretAccessKey(),
                          creds.getSessionToken())))
                  .build();
          return ecrClient.getAuthorizationToken(new GetAuthorizationTokenRequest()
                          .withRegistryIds(registryId))
                  .getAuthorizationData().get(SINGLE_ELEMENT_INDEX)
                  .getAuthorizationToken();
      }
  }
  </code></pre>
  
  <p>Unfortunately, when executing the code, I am getting following exception:</p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalArgumentException: hostname cannot be null
      at com.amazonaws.util.AwsHostNameUtils.parseRegion(AwsHostNameUtils.java:79)
      at com.amazonaws.util.AwsHostNameUtils.parseRegionName(AwsHostNameUtils.java:59)
      at com.amazonaws.auth.internal.AWS4SignerRequestParams.resolveRegion(AWS4SignerRequestParams.java:121)
      at com.amazonaws.auth.internal.AWS4SignerRequestParams.&lt;init&gt;(AWS4SignerRequestParams.java:103)
      at com.amazonaws.auth.AWS4Signer.sign(AWS4Signer.java:225)
      at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1212)
      at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1058)
      at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:743)
      at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:717)
      at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:699)
      at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:667)
      at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:649)
      at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:513)
      at com.amazonaws.services.ecr.AmazonECRClient.doInvoke(AmazonECRClient.java:1742)
      at com.amazonaws.services.ecr.AmazonECRClient.invoke(AmazonECRClient.java:1718)
      at com.amazonaws.services.ecr.AmazonECRClient.executeGetAuthorizationToken(AmazonECRClient.java:992)
      at com.amazonaws.services.ecr.AmazonECRClient.getAuthorizationToken(AmazonECRClient.java:966)
      at com.mycode.utils.ecr.aws.ECRTokenGetter.getEcrAuthorisationToken(ECRTokenGetter.java:27)
      at com.mycode.utils.ecr.AWSAuthTester.main(AWSAuthTester.java:32)
  </code></pre>
  
  <p>I can also observe the request object created by AWS SDK has a NULL host in the entrypoint, as can be seen in the picture below.</p>
  
  <p>DefaultRequest object</p>
  
  <p><a href="https://i.stack.imgur.com/omFdW.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/omFdW.jpg" alt="enter image description here"></a></p>
  
  <p>How can I overcome this issue?</p>