正在查找`Error parsing parameter '--request-items'的解决方案:JSON无效:...`

mzmfm0qo  于 2023-05-30  发布在  其他
关注(0)|答案(1)|浏览(126)

我尝试在CLI中使用AWS Cloud9 IDE在AWS DynamoDB中创建一个表,然后用一个.json文件填充20个项目,并使用CLI将这20个项目上传到DynamoDB表中,并带有各种其他属性。我已经成功地创建了这个表,但是当我把.json文件写到表中时,我收到了一个错误。
在Cloud9的CLI中,我确保我与我的.json文件在同一个目录中。然后跑了
voclabs:~/environment/Homework2 $ aws dynamodb batch-write-item --request-items file://sensor_items.json
返回

Error parsing parameter '--request-items': Invalid JSON:
[
 {
   "Sensor": {"S": "Sensor1"},
   "SensorDescription": {"S": "Description 1"},
   "ImageFile": {"S": "/Sensors/images/sensor1.jpg"},
   "SampleRate": {"N": 2048},
   "Locations": {"SS": ["Aberdeen MD", "Warren MI", "Orlando FL"]}
 },
 {
   "Sensor": {"S": "Sensor2"},
   "SensorDescription": {"S": "Description 2"},
   "ImageFile": {"S": "/Sensors/images/sensor2.jpg"},
   "SampleRate": {"N": 4096},
   "Locations": {"SS": ["New York NY", "Chicago IL"]},
   "SensorFunctional": {"BOOL": true}
 },
 {
    "Sensor": {"S": "Sensor3"},
    "ImageFile": {"S": "/Sensors/images/sensor3.jpg"},
    "SampleRate": {"N": 2829},
    "Locations": {"SS": ["San Fransisco, CA", "Las Vegas, NV"]}
 },....

我在想也许我的.json文件格式不正确,但我还没有找到解决方案。

p4rjhz4m

p4rjhz4m1#

您的JSON与BatchWriteItem预期的有效负载不匹配:

{
   "RequestItems": { 
      "TableName" : [ 
         { 
            "PutRequest": { 
               "Item": { 
                  "string" : { 
                     "B": blob,
                     "BOOL": boolean,
                     "BS": [ blob ],
                     "L": [ 
                        "AttributeValue"
                     ],
                     "M": { 
                        "string" : "AttributeValue"
                     },
                     "N": "string",
                     "NS": [ "string" ],
                     "NULL": boolean,
                     "S": "string",
                     "SS": [ "string" ]
                  }
               }
            }
         }
      ]
   },
   "ReturnConsumedCapacity": "string",
   "ReturnItemCollectionMetrics": "string"
}

https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html
您必须将JSON与PutRequest参数沿着嵌套在表名中。

相关问题