-3

I would like some help; i'm trying to get a certain item from the dynamodb table by calling it with the specific id (primary key) e with a global secondary index called index_book.

The function of interest is as follows:

case "GET /book/{id}":
        body = await dynamo
          .get({
            TableName: "book",
            Key: {
              id: event.pathParameters.id
            }
          })
          .promise();
        break;

The moment I go to call the url with a specific id, so for example /book/7 (where 7 is id) I get the following error:

"The provided key element does not match the schema"

Can you help me please? I will be very grateful to you.

a_l_e_x
  • 408
  • 1
  • 6
  • 20

1 Answers1

2

You cannot do a get item against a GSI, you have to do a query. That's because in a GSI there's no uniqueness constraint and multiple items might have the same partition key / sort key combination.

So switch the get to a query and you'll also need to specify the IndexName.

hunterhacker
  • 6,378
  • 1
  • 14
  • 11