I'm trying to create a custom query type in AppSync to query on a field other than the default id.
Note: I don't have a sort key or a global secondary index configured.
Data source is connected to DynamoDB GameStats table. The record exists in the table but when I query, I get "The provided key element does not match the schema".
query getGameByMeetupId {
getGameByMeetupId(meetupId: "259028625") {
name
field
year
month
}
}
Query:
getGameByMeetupId(meetupId: String): GameStats
Request mapping template:
{
"version": "2017-02-28",
"operation": "GetItem",
"key": {
"meetupId": $util.dynamodb.toDynamoDBJson($ctx.args.meetupId)
}
}
Response mapping template:
$utils.toJson($ctx.result)
Error message:
{
"data": {
"getGameByMeetupId": null
},
"errors": [
{
"path": [
"getGameByMeetupId"
],
"data": null,
"errorType": "DynamoDB:AmazonDynamoDBException",
"errorInfo": null,
"locations": [
{
"line": 2,
"column": 3,
"sourceName": null
}
],
"message": "The provided key element does not match the schema (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: MC71RFG6U85PBICS2OA714TLB7VV4KQNSO5AEMVJF66Q9ASUAAJG)"
}
]
}
To use a DynamoDB Query, you have to specify a value for the partition key.
You mentioned your table has a 'default id' attribute. Is that your partition key? If so, you have two choices:
1) Change the Query to a Scan, and specify a filter on the meetupId attribute
2) Add a GSI, setting meetupId as the partition key, and then update the Query you already have to target the GSI, not the base table
If you're still having trouble, make sure to double check that the resolver is mapped to a data source in AppSync. Mine wasn't attached for some reason, and resulted in the same error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With