Я могу создать таблицу При получении данных в DynamodB в AWS я получаю AccessDeniedException с DynamoDBMapper - PullRequest
0 голосов
/ 22 сентября 2018

Я успешно создал таблицу в AWS DynamodB, но когда я пытаюсь получить данные с помощью «DynamoDBMapper.load ()», я получаю AccessDeniedException

private AmazonDynamoDB client = config.amazonDynamoDB();
private DynamoDBMapper dbMapper = config.dynamoDbMapper(client);
@Value(${SOME_VALUE})
private String tableName;
public void createTable() {
CreateTableRequest request = this.dbMapper
.generateCreateTableRequest(MyEntity.class)
.withTableName(prefix + tableName)
.withProvisionedThroughput(new ProvisionedThroughput(LONG_5, LONG_10));
request.getGlobalSecondaryIndexes().get(0)
.setProvisionedThroughput(new ProvisionedThroughput(LONG_5, LONG_10));
request.getGlobalSecondaryIndexes().get(0)
.setProjection(new Projection().withProjectionType("ALL"));
}
public MyEntity getEntityByName(String name){
MyEntity myEntity = dbMapper.load(MyEntity.class, name);
        return myEntity;
}
  1. иесли используется метод "AmazonDynamoDB.query ()", то я получаю ноль

    public MyEntity getEntityByName(String name){
    Map<String, String> expressionAttributesName = new HashMap<>();
        expressionAttributesName.put("#name", "name");
        Map<String, AttributeValue> expressionAttributesValue = new                 
    HashMap<String, AttributeValue>();
        expressionAttributesValue.put(":name", new         
    AttributeValue().withS(name));
        QueryRequest queryRequest = new QueryRequest()
                .withTableName(prefix + tableName)
                .withIndexName("eventIdIndex")
                .withFilterExpression("#name =:name")
                .withExpressionAttributeNames(expressionAttributesName)
                .withExpressionAttributeValues(expressionAttributesValue);
        QueryResult queryResult = client.query(queryRequest);
        List<Map<String, AttributeValue>> attributeValues = 
    queryResult.getItems();
        LOG.debug("attributeValues items size from DB " + 
    attributeValues.size());
        if (attributeValues.size() > 0) {
        MyEntity myEntity = dbMapper.marshallIntoObject(MyEntity.class,
                attributeValues.get(0));
        return myEntity;
    

    }

...