Scan results are not being filtered correctly in response mapping
0
I have a simple test table with user data with the following schema
type GlobalUsers {
userid: String!
firstname: String
lastname: String
email: AWSEmail
phone: AWSPhone
public: Boolean
}
The listGlobalUsers query with an unfiltered response mapping returns
{
"data": {
"listGlobalUsers": {
"items": [
{
"userid": "janedoe",
"email": "jane.doe@gmail.com",
"phone": "12345678901"
},
{
"userid": "johndoe",
"email": "john.doe@gmail.com",
"phone": "12345678901"
}
]
}
}
}
If I modify the response template to filter on items marked as public
#set($publicRecords = [])
#foreach($item in $ctx.result.items)
#if($item.public == true)
#set($added = $publicRecords.add($item))
#end
#end
$utils.toJson($publicRecords)
The query results are always null
{
"data": {
"listGlobalUsers": {
"items": null
}
}
}
I wonder if I have something configured incorrectly because the results are always null, even if I remove the condition and add all items to $publicRecords
asked 3 years ago0 views
1 Answers
0
I was able to get it to work by setting the value of $ctx.result.items to $publicRecords
The issue was caused by the structure of the result output. Do note that this response template is one of the example templates in the AppSync resolver UI, so it should probably be corrected.
#set($publicRecords = [])
#foreach($item in $ctx.result.items)
#if($item.public == true)
#set($added = $publicRecords.add($item))
#end
#end
#set($ctx.result.items = $publicRecords)
$utils.toJson($ctx.result)
Edited by: raz92 on Jun 26, 2019 4:42 PM
answered 3 years ago
Relevant questions
Access denied error while creating Data Filter in Lake Formation
asked 5 months agoUpdate Records with AWS Glue
asked a month agoText data type column not loading data for the values with hyphen and special charcter
asked 15 days agoAWS scan and query not working as intended
asked 18 days agocrawled data can not be queried in athena
Accepted Answerasked 5 years agoScan results are not being filtered correctly in response mapping
asked 3 years agoMapping multiple values for a requestParameter key
Accepted Answerasked 2 years agoError reading Kinesis table in Zeppelin
asked 3 months agoGlue table not showing in console
asked 2 months agoHow To Detect BatchItemFailure support from Lambda SQS Event
asked 2 months ago