AWS DAX Java身份验证问题

时间:2018-06-22 17:49:58

标签: java authentication aws-sdk amazon-dynamodb-dax

我正在尝试在使用DAX和DynamoDB进行性能测试之间编写一种灵活的身份验证机制。 我已经能够使其在所有区域与DynamoDB正常工作,但它只能在DAX的us-west-1中正常工作。

if (this.useDax) {
  try {
    AWSCredentials credentials = new PropertiesCredentials(new File(credentialsFile));
    ClientConfig daxConfig = new ClientConfig().withEndpoints(endpoint).withRegion(daxRegion)
        .withCredentialsProvider(new AWSStaticCredentialsProvider(credentials));
    daxDB = new ClusterDaxClient(daxConfig);
    primaryKeyName = primaryKey;
    LOGGER.info("dynamodb DAX connection created with " + this.endpoint);
  } catch (Exception e1) {
    LOGGER.error("DaxDBClient.init(): Could not initialize DaxDB client.", e1);
  }
} else {
  try {
    AWSCredentials credentials = new PropertiesCredentials(new File(credentialsFile));
    ClientConfiguration cconfig = new ClientConfiguration();
    cconfig.setMaxConnections(maxConnects);
    dynamoDB = new AmazonDynamoDBClient(credentials, cconfig);
    dynamoDB.setEndpoint(this.endpoint);
    primaryKeyName = primaryKey;
    LOGGER.info("dynamodb connection created with " + this.endpoint);
  } catch (Exception e1) {
    LOGGER.error("DynamoDBClient.init(): Could not initialize DynamoDB client.", e1);
  }
}

我得到的错误是:

  

com.amazon.dax.client.exceptions.DaxServiceException:[1.23.31.33]连接需要身份验证(服务:null;状态代码:-1;错误代码:null;请求ID:null)

1 个答案:

答案 0 :(得分:0)

我最终使用了另一个凭据提供程序(PropertiesFileCredentialsProvider),它可以正常工作:

if (this.useDax) {
  try {
    ClientConfig daxConfig = new ClientConfig().withEndpoints(this.endpoint).withRegion(daxRegion)
        .withCredentialsProvider(new PropertiesFileCredentialsProvider(credentialsFile));
    daxDB = new ClusterDaxClient(daxConfig);
    primaryKeyName = primaryKey;
    LOGGER.info("dynamodb DAX connection created with " + this.endpoint);
  } catch (Exception e1) {
    LOGGER.error("DaxDBClient.init(): Could not initialize DaxDB client.", e1);
  }
} else {
  try {
    AWSCredentials credentials = new PropertiesCredentials(new File(credentialsFile));
    ClientConfiguration cconfig = new ClientConfiguration();
    cconfig.setMaxConnections(maxConnects);
    dynamoDB = new AmazonDynamoDBClient(credentials, cconfig);
    dynamoDB.setEndpoint(this.endpoint);
    primaryKeyName = primaryKey;
    LOGGER.info("dynamodb connection created with " + this.endpoint);
  } catch (Exception e1) {
    LOGGER.error("DynamoDBClient.init(): Could not initialize DynamoDB client.", e1);
  }
}