martin
martin

Reputation: 990

dynamodb "GetItem operation: Requested resource not found" / "The provided key element does not match the schema"

I don't know how to explain this:

$aws dynamodb scan --table-name Todos-dev  
...
{
    "Items": [
        {
            "todoId": {
                "S": "9e6e7f0f-97ee-4289-93b9-cb1bf46d5190"
            },
            "createdAt": {
                "S": "2019-12-29T07:11:09.581Z"
            },
            "name": {
                "S": "test4"
            },
            "userId": {

and

$ aws dynamodb get-item --table-name Todos.dev --key file://key.json

An error occurred (ResourceNotFoundException) when calling the GetItem operation: Requested resource not found

where

$ cat key.json 
{"todoId": {"S": "9e6e7f0f-97ee-4289-93b9-cb1bf46d5190"}}

serverless.yml

    TodosTable:
      Type: AWS::DynamoDB::Table
      Properties:
        AttributeDefinitions:
          - AttributeName: todoId
            AttributeType: S
          - AttributeName: createdAt
            AttributeType: S
          - AttributeName: dueDate
            AttributeType: S
        KeySchema:
          - AttributeName: todoId
            KeyType: HASH
          - AttributeName: createdAt
            KeyType: RANGE
        BillingMode: PAY_PER_REQUEST
        TableName: ${self:provider.environment.TODOS_TABLE}
        LocalSecondaryIndexes:
          - IndexName: ${self:provider.environment.INDEX_NAME}
            KeySchema:
              - AttributeName: todoId
                KeyType: HASH
              - AttributeName: dueDate
                KeyType: RANGE
            Projection:
              ProjectionType: ALL

The message I'm getting "The provided key element does not match the schema", comes from docClient.delete, tried multiple combinations to specify Key, nothing works.

Upvotes: 1

Views: 1273

Answers (1)

Matthew Pope
Matthew Pope

Reputation: 7679

key element does not match schema

Your table has a hash key and a range key. Your key.json file has only the hash key. When using getItem, you must provide the full (hash and range) key. If you want to get multiple values for the same hash key or if the range key value is unknown, you can use only the hash key, but you must use they query api instead.

resource not found

You are using Todos-dev in your scan call, but Todos.dev in the getItem call.

Upvotes: 2

Related Questions