AWS Dynamodb中的queryRequest存在问题

时间:2019-06-04 01:21:34

标签: amazon-web-services amazon-dynamodb

我在使用dynamodb和QueryRequest时遇到问题。我想用dynamodb实现分页。

我从邮递员那里收到错误消息。向右滚动以查看完整错误。

{
"timestamp": "2019-06-04T00:12:42.526+0000",
"status": 500,
"error": "Internal Server Error",
"exception": "com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException",
"message": "Request processing failed; nested exception is com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException: Requested resource not found (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ResourceNotFoundException; Request ID: TDAUFVG205A11TFDGOD9U53MMBVV4KQNSO5AEMVJF66Q9ASUAAJG)", 

我的项目确实与其他api的获取连接并正常工作。 dynamoDBMapper.query可以正常工作并返回数据。

问题出在使用QueryRequest的新代码中。

public String getRequestPage(String query,  String lastEvaluatedKey, String limit) {

...
Map<String, AttributeValue> mapLastEvaluatedKey = null;

Map<String,String> expressionAttributesNames = new HashMap<>();
expressionAttributesNames.put("#tagId","tagId");

Map<String,AttributeValue> expressionAttributeValues = new HashMap<>();
expressionAttributeValues.put(":column_search",new AttributeValue().withS(query));

QueryRequest queryRequest = new QueryRequest()
  .withTableName(dynamoDbTableName)
  .withKeyConditionExpression("#tagId = :column_search") 
  .withExpressionAttributeNames(expressionAttributesNames)
  .withExpressionAttributeValues(expressionAttributeValues)
  .withLimit(page_limit)
  .withExclusiveStartKey(mapLastEvaluatedKey);

System.out.println(" queryRequest " + queryRequest  );

QueryResult queryResult = client.query(queryRequest);

Map<String, AttributeValue> mapLastEvaluatedKeyReturned = null;
mapLastEvaluatedKeyReturned = queryResult.getLastEvaluatedKey();


  error -->{ "timestamp": "2019-06-04T19:58:18.156+0000", "status": 500, 
  "error": "Internal Server Error", "exception": 
   "com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException", 
   "message": "Request processing failed; nested exception is 
    com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException: 
    Requested resource not found (Service: AmazonDynamoDBv2; Status Code: 
    400; Error Code: ResourceNotFoundException; Request ID: 
    BRCI1FLM3375SB8U6JSJEAH09NVV4KQNSO5AEMVJF66Q9ASUAAJG)", "path": 
     "/api/v1/metadata/tag/tagIdPage/military_status/page/1/limit/2" } 

这是queryRequest中的system.out,并发送到DB

  queryRequest {TableName: tagMetadata_Certified-dev,Limit: 
   2,FilterExpression: tagId = :tagIdValue,KeyConditionExpression: #tagId = :tagIdValue,ExpressionAttributeNames: 
   {#tagId=tagId},ExpressionAttributeValues: {:tagIdValue={S: 
   military_status,}}}

任何帮助都会很棒。

谢谢 菲尔

1 个答案:

答案 0 :(得分:0)

我从终端窗口中使用aws cli发出了我的证书。这对于使用--debug开关进行测试非常有用。

向右滚动以获取完整代码...

 aws dynamodb query --table-name tableNameHere  --region regionNameHere --key-condition-expression "tagId = :tagIdValue"  --filter-expression "isReportable = :p" --expression-attribute-values '{":tagIdValue":{"S":"m_status"}, ":p":{"BOOL":true}}' --debug



public String getRequestPage(String tagIdPassed,  String lastEvaluatedKey, String limit) {
.... code removed ...

Boolean isReportableBool = true;

TagMetadata tagMetadata = new TagMetadata();

Map<String,String> expressionAttributesNames = new HashMap<>();
expressionAttributesNames.put("#tagId","tagId");
expressionAttributesNames.put("#isReportable","isReportable");

Map<String,AttributeValue> expressionAttributeValues = new HashMap<>();
expressionAttributeValues.put(":tagIdValue",new AttributeValue().withS(tagIdPassed));
expressionAttributeValues.put(":isReportableValue",new AttributeValue().withBOOL(isReportableBool));

QueryRequest queryRequest = new QueryRequest()
  .withTableName(dynamoDbTableName)
  .withKeyConditionExpression("#tagId = :tagIdValue")
  .withFilterExpression("#isReportable = :isReportableValue")
  .withExpressionAttributeNames(expressionAttributesNames)
  .withExpressionAttributeValues(expressionAttributeValues)
  .withLimit(page_limit);