-1

Environment: AWS Cloud9, Dynamodb, Tables, .json files, Python.

I am trying to call a .json file with the command aws dynamodb batch-write-item --request-items file://TestCLI/Sensors.json

This json file is trying to create multiple items within a table and I believe there is an issue with my design. When originally testing the json file with only one section/input, it worked fine. Since I have added multiple inputs, it isn't working correctly.

Here is the .json file text

{
   "ImageFile": {"S": "/Images/Bears.png"},
   "SenorDescription": {"S": "Chicago Bears"},
   "SampleRate": {"N": "2020" },
   "Sensor": {"S": "001"},
   "Locations": {"S":"Chicago IL"}
},
{
   "ImageFile": {"S": "/Images/Bengals.png"},
   "SenorDescription": {"S": "Cincinnati Bengals"},
   "SampleRate": {"N": "2021" },
   "Sensor": {"S": "002"},
   "Locations": {"S":"Cincinnati OH"}
},
{
   "ImageFile": {"S": "/Images/Bills.png"},
   "SenorDescription": {"S": "Buffalo Bills"},
   "SampleRate": {"N": "2022" },
   "Sensor": {"S": "003"},
   "Locations": {"S":"Orchard Park NY"}
},
{
   "ImageFile": {"S": "/Images/Broncos.png"},
   "SenorDescription": {"S": "Denver Broncos"},
   "SampleRate": {"N": "2023" },
   "Sensor": {"S": "004"},
   "Locations": {"S":"Denver CO"}
},
{
   "ImageFile": {"S": "/Images/Browns.png"},
   "SenorDescription": {"S": "Cleveland Browns"},
   "SampleRate": {"N": "2024" },
   "Sensor": {"S": "005"},
   "Locations": {"S":"Cleveland OH"}
},
{
   "ImageFile": {"S": "/Images/Cardinals.png"},
   "SenorDescription": {"S": "Arizona Cardinals"},
   "SampleRate": {"N": "2025" },
   "Sensor": {"S": "006"},
   "Locations": {"S":"Glendale AR"}
},
{
   "ImageFile": {"S": "/Images/Chiefs.png"},
   "SenorDescription": {"S": "Kansas City Chiefs"},
   "SampleRate": {"N": "2026" },
   "Sensor": {"S": "007"},
   "Locations": {"S":"Kansas City MO"}
},
{
   "ImageFile": {"S": "/Images/Colts.png"},
   "SenorDescription": {"S": "Indianapolis Colts"},
   "SampleRate": {"N": "2027" },
   "Sensor": {"S": "008"},
   "Locations": {"S":"Indianapolis IN"}
},
{
   "ImageFile": {"S": "/Images/Cowboys.png"},
   "SenorDescription": {"S": "Dallas Cowboys"},
   "SampleRate": {"N": "2028" },
   "Sensor": {"S": "009"},
   "Locations": {"S":"Dallas TX"}
},
{
   "ImageFile": {"S": "/Images/Falcons.png"},
   "SenorDescription": {"S": "Atlanta Falcons"},
   "SampleRate": {"N": "2029" },
   "Sensor": {"S": "010"},
   "Locations": {"S":"Atlanta GA"}
},
{
   "ImageFile": {"S": "/Images/Jaguars.png"},
   "SenorDescription": {"S": "Jacksonville Jaguars"},
   "SampleRate": {"N": "2030" },
   "Sensor": {"S": "011"},
   "Locations": {"S":"Jacksonville FL"}
},
{
   "ImageFile": {"S": "/Images/Lions.png"},
   "SenorDescription": {"S": "Detroit Lions"},
   "SampleRate": {"N": "2031" },
   "Sensor": {"S": "012"},
   "Locations": {"S":"Detroit MI"}
},
{
   "ImageFile": {"S": "/Images/Packers.png"},
   "SenorDescription": {"S": "Greeb Bay Packers"},
   "SampleRate": {"N": "2032" },
   "Sensor": {"S": "013"},
   "Locations": {"S":"Green Bay WI"}
},
{
   "ImageFile": {"S": "/Images/Panthers.png"},
   "SenorDescription": {"S": "Carolina Panthers"},
   "SampleRate": {"N": "2033" },
   "Sensor": {"S": "014"},
   "Locations": {"S":"Charlotte NC"}
},
{
   "ImageFile": {"S": "/Images/Raiders.png"},
   "SenorDescription": {"S": "Las Vegas Raiders"},
   "SampleRate": {"N": "2034" },
   "Sensor": {"S": "015"},
   "Locations": {"S":"Las Vegas NV"}
},
{
   "ImageFile": {"S": "/Images/Rams.png"},
   "SenorDescription": {"S": "Los Angeles Rams"},
   "SampleRate": {"N": "2035" },
   "Sensor": {"S": "016"},
   "Locations": {"S":"Los Angeles CA"}
},
{
   "ImageFile": {"S": "/Images/Ravens.png"},
   "SenorDescription": {"S": "Baltimore Ravens"},
   "SampleRate": {"N": "2036" },
   "Sensor": {"S": "017"},
   "Locations": {"S":"Baltimore MD"}
},
{
   "ImageFile": {"S": "/Images/Saints.png"},
   "SenorDescription": {"S": "New Orleans Saints"},
   "SampleRate": {"N": "2037" },
   "Sensor": {"S": "018"},
   "Locations": {"S":"New Orleans LA"}
},
{
   "ImageFile": {"S": "/Images/Texans.png"},
   "SenorDescription": {"S": "Houston Texans"},
   "SampleRate": {"N": "2038" },
   "Sensor": {"S": "019"},
   "Locations": {"S":"Houston TX"}
},
{
   "ImageFile": {"S": "/Images/Vikings.png"},
   "SenorDescription": {"S": "Minnesota Vikings"}
   "SampleRate": {"N": "2039" },
   "Sensor": {"S": "020"},
   "Locations": {"S":"Minnesota MN"}
}

Here is Error message

Error parsing parameter '--request-items': Invalid JSON: Extra data: line 7 column 2 - line 140 column 2 (char 194 - 4046)
JSON received: {
   "ImageFile": {"S": "/Images/Bears.png"},
   "SenorDescription": {"S": "Chicago Bears"},
   "SampleRate": {"N": "2020" },
   "Sensor": {"S": "001"},
   "Locations": {"S":"Chicago IL"}
},
{
   "ImageFile": {"S": "/Images/Bengals.png"},
   "SenorDescription": {"S": "Cincinnati Bengals"},
   "SampleRate": {"N": "2021" },
   "Sensor": {"S": "002"},
   "Locations": {"S":"Cincinnati OH"}
},
{
   "ImageFile": {"S": "/Images/Bills.png"},
   "SenorDescription": {"S": "Buffalo Bills"},
   "SampleRate": {"N": "2022" },
   "Sensor": {"S": "003"},
   "Locations": {"S":"Orchard Park NY"}
},
{
   "ImageFile": {"S": "/Images/Broncos.png"},
   "SenorDescription": {"S": "Denver Broncos"},
   "SampleRate": {"N": "2023" },
   "Sensor": {"S": "004"},
   "Locations": {"S":"Denver CO"}
},
{
   "ImageFile": {"S": "/Images/Browns.png"},
   "SenorDescription": {"S": "Cleveland Browns"},
   "SampleRate": {"N": "2024" },
   "Sensor": {"S": "005"},
   "Locations": {"S":"Cleveland OH"}
},
{
   "ImageFile": {"S": "/Images/Cardinals.png"},
   "SenorDescription": {"S": "Arizona Cardinals"},
   "SampleRate": {"N": "2025" },
   "Sensor": {"S": "006"},
   "Locations": {"S":"Glendale AR"}
},
{
   "ImageFile": {"S": "/Images/Chiefs.png"},
   "SenorDescription": {"S": "Kansas City Chiefs"},
   "SampleRate": {"N": "2026" },
   "Sensor": {"S": "007"},
   "Locations": {"S":"Kansas City MO"}
},
{
   "ImageFile": {"S": "/Images/Colts.png"},
   "SenorDescription": {"S": "Indianapolis Colts"},
   "SampleRate": {"N": "2027" },
   "Sensor": {"S": "008"},
   "Locations": {"S":"Indianapolis IN"}
},
{
   "ImageFile": {"S": "/Images/Cowboys.png"},
   "SenorDescription": {"S": "Dallas Cowboys"},
   "SampleRate": {"N": "2028" },
   "Sensor": {"S": "009"},
   "Locations": {"S":"Dallas TX"}
},
{
   "ImageFile": {"S": "/Images/Falcons.png"},
   "SenorDescription": {"S": "Atlanta Falcons"},
   "SampleRate": {"N": "2029" },
   "Sensor": {"S": "010"},
   "Locations": {"S":"Atlanta GA"}
},
{
   "ImageFile": {"S": "/Images/Jaguars.png"},
   "SenorDescription": {"S": "Jacksonville Jaguars"},
   "SampleRate": {"N": "2030" },
   "Sensor": {"S": "011"},
   "Locations": {"S":"Jacksonville FL"}
},
{
   "ImageFile": {"S": "/Images/Lions.png"},
   "SenorDescription": {"S": "Detroit Lions"},
   "SampleRate": {"N": "2031" },
   "Sensor": {"S": "012"},
   "Locations": {"S":"Detroit MI"}
},
{
   "ImageFile": {"S": "/Images/Packers.png"},
   "SenorDescription": {"S": "Greeb Bay Packers"},
   "SampleRate": {"N": "2032" },
   "Sensor": {"S": "013"},
   "Locations": {"S":"Green Bay WI"}
},
{
   "ImageFile": {"S": "/Images/Panthers.png"},
   "SenorDescription": {"S": "Carolina Panthers"},
   "SampleRate": {"N": "2033" },
   "Sensor": {"S": "014"},
   "Locations": {"S":"Charlotte NC"}
},
{
   "ImageFile": {"S": "/Images/Raiders.png"},
   "SenorDescription": {"S": "Las Vegas Raiders"},
   "SampleRate": {"N": "2034" },
   "Sensor": {"S": "015"},
   "Locations": {"S":"Las Vegas NV"}
},
{
   "ImageFile": {"S": "/Images/Rams.png"},
   "SenorDescription": {"S": "Los Angeles Rams"},
   "SampleRate": {"N": "2035" },
   "Sensor": {"S": "016"},
   "Locations": {"S":"Los Angeles CA"}
},
{
   "ImageFile": {"S": "/Images/Ravens.png"},
   "SenorDescription": {"S": "Baltimore Ravens"},
   "SampleRate": {"N": "2036" },
   "Sensor": {"S": "017"},
   "Locations": {"S":"Baltimore MD"}
},
{
   "ImageFile": {"S": "/Images/Saints.png"},
   "SenorDescription": {"S": "New Orleans Saints"},
   "SampleRate": {"N": "2037" },
   "Sensor": {"S": "018"},
   "Locations": {"S":"New Orleans LA"}
},
{
   "ImageFile": {"S": "/Images/Texans.png"},
   "SenorDescription": {"S": "Houston Texans"},
   "SampleRate": {"N": "2038" },
   "Sensor": {"S": "019"},
   "Locations": {"S":"Houston TX"}
},
{
   "ImageFile": {"S": "/Images/Vikings.png"},
   "SenorDescription": {"S": "Minnesota Vikings"}
   "SampleRate": {"N": "2039" },
   "Sensor": {"S": "020"},
   "Locations": {"S":"Minnesota MN"}
}
Dreed66
  • 25
  • 1
  • 5
  • Your json file syntax is wrong. See the [docs](https://docs.aws.amazon.com/cli/latest/reference/dynamodb/batch-write-item.html#options) with example. – DeepSpace Jul 13 '23 at 16:10

1 Answers1

0

You can't just use the JSON Item you must also specify the additional details which you can see from the BatchWriteItem API docs request syntax:

https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html

Leeroy Hannigan
  • 11,409
  • 3
  • 14
  • 31