0

我想在 Java 本地的 DynamoDB 中做一些 CRUD 操作。我没有任何 aws 凭据。我已经完成了设置本地环境的所有设置,还创建了表,也可以在 aws CLI 中查看。

已经参考了在没有 AWS 凭证的情况下在您的计算机上使用 DynamoDB问题,但它没有执行这些操作的 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"

谁能帮我解决这个问题。

4

1 回答 1

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();
于 2018-08-20T11:51:18.937 回答