AWS AppSync解析程序中的FilterExpression语法错误无效

时间:2018-05-21 07:47:04

标签: amazon-web-services amazon-dynamodb aws-appsync

我有以下解析程序,可以通过IN运算符组合的ID列表来获取项目。

{
"version" : "2017-02-28",
"operation" : "Query",
"query" : {
    ## Provide a query expression. **
    "expression": "studentId = :id",
    "expressionValues" : {
        ":id" : { "S": "$ctx.args.studentId" }
    }
},
"filter": {
    "expression": "topicId IN :ids",
    "expressionValues" : {
        ":ids" : { "NS" : $ctx.args.topicIds }
    }
},
"index": "studentId-index",
}

收到以下错误:

{
"data": {
   "listStudentBookmarkedTopics": null
 },
 "errors": [
{
  "path": [
    "listStudentBookmarkedTopics"
  ],
  "data": null,
  "errorType": "DynamoDB:AmazonDynamoDBException",
  "errorInfo": null,
  "locations": [
    {
      "line": 2,
      "column": 3
    }
  ],
  "message": "Invalid FilterExpression: Syntax error; token: \":ids\", near: 
  \"IN :ids\" (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: 
  ValidationException; Request ID: 
   R49QUD5LDF7KS83ABNTPLP10RBVV4KQNSO5AEMVJF66Q9ASUAAJG)"
  }
]
}

1 个答案:

答案 0 :(得分:1)

您可以尝试将过滤器表达式更改为以下内容吗?

"filter": {
    "expression": "contains(:ids, topicId)",
    "expressionValues" : {
        ":ids" : { "NS" : $util.toJson($ctx.args.topicIds) }
    }
}

这会添加对 $ util.toJson 的调用,并使用包含 DynamoDB过滤器表达式。