1

我正在尝试在使用 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)

4

1 回答 1

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);
  }
}
于 2018-06-22T22:02:54.940 回答