首页 > 解决方案 > 使用 CLI 时如何解决 AWS DynamoDB 中的 (ValidationException) 问题?

问题描述

我刚刚在 CLI 中学习 AWS DynamoDB。我是专门put-item使用 command 执行的 aws dynamodb put-item --table-name new --item file://item.json。我已经成功配置了 IAM 凭证,我还可以使用以下方法获得回复 aws dynamodb list-tables

{ "TableNames": [ "new", "test" ] }

错误:

验证错误

我特别是这个错误:An error occurred (ValidationException) when calling the PutItem operation: One or more parameter values were invalid: Missing the key newid in the item

谁能指导我如何摆脱这个并修复这个错误?

标签: amazon-web-servicesaws-lambdaamazon-dynamodbputdynamo-local

解决方案


好的,我是提出这个问题的人,感谢@krishna_mee2004提示我的问题。主要问题是我已将分区键指定为test_id并且我将其用作user_id.

我以前的格式item.json

    {
    "user_id":{"S":"123add"},
    "ForumName": {"S": "Amazon DynamoDB"},
    "Subject": {"S": "New discussion thread"},
    "Message": {"S": "First post in this thread"},
    "LastPostedBy": {"S": "fred@example.com"},
    "LastPostDateTime": {"S": "201603190422"}
}

但我只是替换user_idtest_id

   {
    "test_id":{"S":"123add"},
    "ForumName": {"S": "Amazon DynamoDB"},
    "Subject": {"S": "New discussion thread"},
    "Message": {"S": "First post in this thread"},
    "LastPostedBy": {"S": "fred@example.com"},
    "LastPostDateTime": {"S": "201603190422"}
}

这是我的 AWS DynamoDB 表的实际分区键,瞧,它起作用了:

我成功创建了一个表列表:

在此处输入图像描述


推荐阅读