0

I'm trying to add items to dynamodb by CLI using batch-write-item but receiving the error: "An error occurred (ValidationException) when calling the BatchWriteItem operation: The provided key element does not match the schema".

I'm using as reference the sample JSON from AWS docs.

Any clue what is missing?

{
   "VertexMasterData":[
      {
         "PutRequest":{
            "Item":{
               "MasterDataID":{
                  "S":"0"
               },
               "ScenarioID":{
                  "S":"1"
               },
               "FlexibleFields":{
                  "M":{
                     "@fieldId4":{
                        "S":"4"
                     },
                     "@fieldId1":{
                        "S":"8517.12.31"
                     }
                  }
               },
               "Seller":{
                  "M":{
                     "MainDivision":{
                        "S":"SP"
                     }
                  }
               },
               "Destination":{
                  "M":{
                     "MainDivision":{
                        "S":"RJ"
                     }
                  }
               }
            }
         }
      },
      {
         "PutRequest":{
            "Item":{
               "MasterDataID":{
                  "S":"1"
               },
               "ScenarioID":{
                  "S":"1"
               },
               "FlexibleFields":{
                  "M":{
                     "@fieldId4":{
                        "S":"1"
                     },
                     "@fieldId1":{
                        "S":"3403.99.00"
                     }
                  }
               },
               "Seller":{
                  "M":{
                     "MainDivision":{
                        "S":"SP"
                     }
                  }
               },
               "Destination":{
                  "M":{
                     "MainDivision":{
                        "S":"AC"
                     }
                  }
               }
            }
         }
      },
      {
         "PutRequest":{
            "Item":{
               "MasterDataID":{
                  "S":"2"
               },
               "ScenarioID":{
                  "S":"1"
               },
               "FlexibleFields":{
                  "M":{
                     "@fieldId4":{
                        "S":"1"
                     },
                     "@fieldId1":{
                        "S":"3506.10.90"
                     }
                  }
               },
               "Seller":{
                  "M":{
                     "MainDivision":{
                        "S":"SP"
                     }
                  }
               },
               "Destination":{
                  "M":{
                     "MainDivision":{
                        "S":"AC"
                     }
                  }
               }
            }
         }
      }
   ]
}

Table details: VertexMasterData

2 Answers 2

0

It looks like your records don't contain the primary key value or values. When you created the VertexMasterData table, you would have designated a Partition Key and possibly also a Sort Key. Any records added to that table must contain your primary key (all other fields are optional), which may be one or two fields.

To see the Partition Key and Sort Key for your table, go to AWS Console > DynamoDb > Tables.

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

1 Comment

Hi Shawn, my Partition and Sort key are MasterDataID and ScenarioID, respectively. Both are being provided in each 3 PutRequest Item! I'm felling that it is something in the layout related with fields type "M"... anyway, thanks for the analysis =)
0

There is a space in the end of Partition key that I'm not considering in the JSON: Table: "MasterDataID " JSON: "MasterDataID"

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.