如何在AppSync中提供对单个项目的细粒度访问。我有以下用于GetItem操作的解析器。
{
"version": "2017-02-28",
"operation": "GetItem",
"key": {
"identityId": $util.dynamodb.toDynamoDBJson($ctx.args.identityId),
"id": $util.dynamodb.toDynamoDBJson($ctx.args.id),
},
"condition": {
"expression": "attribute_exists(#author) AND #author = :author",
"expressionNames": {
"#identityId": "identityId",
"#id": "id",
"#author": "author"
},
"expressionValues": {
":author" : { "S" : "${ctx.identity.cognitoIdentityId}" }
}
}
}
但是,当我运行查询时,我得到了:
GraphQL error: Unsupported element '$[condition]'.
我的问题 如果我不能设置条件,如何过滤/限制对属于特定作者的项目的访问(精细访问)?
答案 0 :(得分:2)
您可以在如下的响应映射模板中过滤结果。据我了解,您正在从cognitoIdentityId获取author字段,并且您的商品具有不同的主键,因此为什么在查询时不能使用author。
#if($context.result["author"] == $ctx.identity.cognitoIdentityId)
$utils.toJson($context.result);
#else
$utils.unauthorized()
#end