Skip to content

AppSync Inconsistency: BatchGetItem Requires DynamoDB Table Name Instead of Data Source Name

0

While using AWS AppSync to query DynamoDB with BatchGetItem, I encountered an inconsistency in how AppSync handles data source mapping. Unlike GetItem, which works correctly with the AppSync data source name, BatchGetItem unexpectedly requires the actual DynamoDB table name instead.

  • No documentation explicitly states that BatchGetItem must use the raw table name.
  • This lack of consistency confuses developers who expect uniform behavior across AppSync operations. Does anybody else have had the same problem? Thanks for the attention.
1 Answer
0

You've identified a key aspect of how BatchGetItem works in AWS AppSync. When using BatchGetItem, you must indeed specify the actual DynamoDB table names as keys in the "tables" map, not the AppSync data source names.

This is by design in the BatchGetItem operation. According to the documentation, the "tables" field in BatchGetItem is a map where the table names (not data source names) are specified as the keys. The documentation states: "The DynamoDB tables to retrieve the items from. The value is a map where table names are specified as the keys of the map."

If your mapping template doesn't match the actual DynamoDB table structure, you'll likely encounter errors like "The provided key element does not match the schema" with a 400 status code.

This behavior differs from single-item operations like GetItem, which can work with the AppSync data source configuration. The difference exists because BatchGetItem is designed to retrieve items from multiple tables in a single operation, so it needs to explicitly reference the actual DynamoDB table names.

To resolve this issue, ensure your BatchGetItem request uses the actual DynamoDB table names in the "tables" map, not your AppSync data source names.
Sources
BatchGetItem - AWS AppSync
BatchGetItem - AWS AppSync
BatchGetItem - AWS AppSync Events
Troubleshooting and common mistakes in AWS AppSync - AWS AppSync

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.