我想在Java本地DynamoDB中执行一些CRUD操作。我没有任何AWS凭证。我已经完成了所有设置以设置本地环境,还创建了表并可以在aws CLI中看到。
已经提到了Working on DynamoDB in your computer without AWS credentials问题,但是没有Java代码示例可以进行操作。
我尝试了代码,
AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.defaultClient();
try {
ddb.deleteTable("book");
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
但这会导致错误
"The AWS Access Key Id needs a subscription for the service"
有人可以帮我吗?
答案 0 :(得分:0)
尝试像这样创建客户端,然后即可执行CRUD操作,
AmazonDynamoDB dynamoDBClient = AmazonDynamoDBClientBuilder.standard().build();
AWSCredentialsProvider credentialsProvide = new DefaultAWSCredentialsProviderChain();
AmazonDynamoDBClientBuilder clientBuilder = AmazonDynamoDBClientBuilder.standard();
clientBuilder.setCredentials(credentialsProvide);
EndpointConfiguration endpointConfiguration = new EndpointConfiguration("http://localhost:8000/", "local");
clientBuilder.setEndpointConfiguration(endpointConfiguration);
dynamoDBClient = clientBuilder.build();