3

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)"
    }
  ]
}

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for clarifying @stu. Makes total sense now.
How do I target the GSI and not the base table?
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.