我正在编写一个功能测试用例并连接到其中的本地 DyanmoDB 实例。
这就是我创建 DynamoDB 客户端的方式:
private static final String table_name = "table-A";
private static String aws_region = "us-west-2";
private static AmazonDynamoDB amazonDynamoDBClient;
private static DynamoDB dynamoDB;
public static void initDB() {
amazonDynamoDBClient = AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration(
new AwsClientBuilder.EndpointConfiguration("http://localhost:8000", aws_region)).build();
dynamoDB = new DynamoDB(amazonDynamoDBClient);
}
这就是我试图创建表的方式:
Table table = dynamoDB.createTable(table_name,
Arrays.asList(new KeySchemaElement("row_name", KeyType.HASH),
new KeySchemaElement("row_id", KeyType.RANGE)),
Arrays.asList(new AttributeDefinition("row_name", ScalarAttributeType.S),
new AttributeDefinition("row_id", ScalarAttributeType.S)),
new ProvisionedThroughput(10L, 10L));
但是,我得到以下异常:
com.amazonaws.SdkClientException: Unable to load AWS credentials from any provider in the chain
at com.amazonaws.auth.AWSCredentialsProviderChain.getCredentials(AWSCredentialsProviderChain.java:131)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.getCredentialsFromContext(AmazonHttpClient.java:1115)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.runBeforeRequestHandlers(AmazonHttpClient.java:764)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:728)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:721)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:704)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:672)
at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:654)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:518)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.doInvoke(AmazonDynamoDBClient.java:1831)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:1807)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.createTable(AmazonDynamoDBClient.java:636)
at com.amazonaws.services.dynamodbv2.document.DynamoDB.createTable(DynamoDB.java:96)
at com.amazonaws.services.dynamodbv2.document.DynamoDB.createTable(DynamoDB.java:108)
at util.DBUtil.createAndInsertTestCases(DBUtil.java:24)
at test.DocumentTest.createAndInsertDataInDB(DocumentTest.java:37)
问题是什么?