DynamoDB Connection使用AWS Java SDK进行Biulding,方法是在运行时从用户处获取Keys

问题描述 投票:2回答:1

我正在尝试通过从用户获取AccessID和SecretKey来连接到DynamoDB。 AmazonDynamoDBClient已被弃用,并且替换不允许我从用户获取凭据并建立与DynamoDB的连接。这是我的代码片段。我得到的解决方案是将密钥保存在本地文件中。我不需要这个。

        DynamoDB dynamoDB = null;

    try {
        System.out.println(1);
        BasicAWSCredentials awsCreds = new BasicAWSCredentials(upDoc.getAccID(), upDoc.getAccKey());
        System.out.println(2);
        //AmazonDynamoDBClient is depreciated  
        AmazonDynamoDBClient client = new AmazonDynamoDBClient(awsCreds).withRegion(Regions.US_EAST_2);
        System.out.println(3);
        dynamoDB = new DynamoDB(client);
        writer.append("Access Granted By AWS DynamoDB \n");
    }catch(AmazonDynamoDBException e) {
        writer.append("Access Denied By AWS DynamoDB \n");
        writer.close();
        return "Error occured. Kindly check logs to get the actual cause!";         
    }
amazon-web-services amazon-dynamodb
1个回答
0
投票

使用AmazonDynamoDBClientBuilder

BasicAWSCredentials awsCreds = new BasicAWSCredentials(upDoc.getAccID(), upDoc.getAccKey());
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().withRegion(Regions.US_EAST_2).withCredentials(awsCreds).build();
© www.soinside.com 2019 - 2024. All rights reserved.