获取AmazonDynamoDBException:用户:arn:aws:iam:USER无权执行:dynamodb:ListTables

问题描述

在DynamoDB配置和连接尝试时,我正在努力解决AmazonDynamoDBException的问题。 配置代码如下:

@AllArgsConstructor
@Configuration
public class AWSDynamoDBConfig {

    private final String accessKey;
    private final String secretKey;
    private final String roleArn;

    public AWSDynamoDBConfig() throws IOException {
        Properties properties = readProperties("common","aws.properties");
        accessKey = properties.getProperty("aws.accessKey");
        secretKey = properties.getProperty("aws.secretKey");
        roleArn = properties.getProperty("aws.roleArn");
    }

    public AssumeRoleRequest roleRequest() {
        return new AssumeRoleRequest().withRoleArn(roleArn);
    }

    @Bean
    public AmazonDynamoDB amazonDynamoDB() {
        return AmazonDynamoDBClientBuilder
                .standard()
                .withRegion(Regions.EU_WEST_1)
                .withCredentials(amazonAWSCredentialProvider())
                .build();
    }

    @Bean
    public AWSCredentials amazonAWSCredential() {
        return new BasicAWSCredentials(accessKey,secretKey);
    }

    @Bean
    public DynamoDBMapperConfig dynamoDBMapperConfig() {
        return DynamoDBMapperConfig.DEFAULT;
    }

    @Bean
    public DynamoDBMapper dynamoDBMapper(AmazonDynamoDB amazonDynamoDB,DynamoDBMapperConfig config) {
        return new DynamoDBMapper(amazonDynamoDB,config);
    }

    @Bean
    public DynamoDB dynamoDB() {
        return new DynamoDB(amazonDynamoDB());
    }

    public AWSCredentialsProvider amazonAWSCredentialProvider() {
        return new AWSStaticCredentialsProvider(amazonAWSCredential());
    }

}

在方法调用listTables

时产生错误
public void listMyTables() {
        TableCollection<ListTablesResult> tables = awsDynamoDBConfig.dynamoDB().listTables();
        Iterator<Table> iterator = tables.iterator();

        log.info("Listing tables from DynamoDB instance");
        while (iterator.hasNext()) {
            Table table = iterator.next();
            log.info("Table name: " + table.getTableName());
        }
    }

com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException:用户:arn:aws:iam :: number:user / machine-USER无权执行:dynamodb:List资源表:arn:aws:dynamodb:eu -west-1:number:table / *(服务:AmazonDynamoDBv2;状态代码:400;错误代码:AccessDeniedException;请求ID:ID-Number)

据我所知,我在AmazonDynamoDB对象中缺少roleArn,所以这就是为什么要添加它的原因。 到目前为止,我已经找到了一个主题click,但是以上解决方案使用了不推荐使用的对象AWSSecurityTokenServiceClient,毕竟,我会使用新的对象AmazonDynamoDB,但是我没有找到使它变为现实的方法。
对于如何向arnRole对象添加缺少的AmazonDynamoDB以完成配置步骤并建立连接的建议,我将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)