Reputation: 103
I am trying to put items within the table and getting this error:
This is the objects.json file I am trying to insert into the db:
{
"Sensors":{
"L": [
{ "M": {
"Sensor": { "S": "Sensor1" },
"SensorDescription": { "S": "This is a description of a Sensor"},
"ImageFile": {"S": "/Sensors/image/Sensor1.txt"},
"SampleRate": {"N": "1"},
"Locations": {"S": "Orlando, FL"}
}
},
{ "M": {
"Sensor": { "S": "Sensor2" },
"SensorDescription": { "S": "This is a description of a Sensor"},
"ImageFile": {"S": "/Sensors/image/Sensor2.txt"},
"SampleRate": {"N": "2"},
"Locations": {"S": "Annapolis, MD"}
}
},
{ "M": {
"Sensor": { "S": "Sensor3" },
"SensorDescription": { "S": "This is a description of a Sensor"},
"ImageFile": {"S": "/Sensors/image/Sensor3.txt"},
"SampleRate": {"N": "3"},
"Locations": {"S": "Jacksonville, FL"}
}
},
{ "M": {
"Sensor": { "S": "Sensor4" },
"SensorDescription": { "S": "This is a description of a Sensor"},
"ImageFile": {"S": "/Sensors/image/Sensor4.txt"},
"SampleRate": {"N": "4"},
"Locations": {"S": "Balitimore, MD"}
}
},
{ "M": {
"Sensor": { "S": "Sensor5" },
"SensorDescription": { "S": "This is a description of a Sensor"},
"ImageFile": {"S": "/Sensors/image/Sensor5.txt"},
"SampleRate": {"N": "5"},
"Locations": {"S": "Washington DC"}
}
},
{ "M": {
"Sensor": { "S": "Sensor6" },
"SensorDescription": { "S": "This is a description of a Sensor"}
}
},
{ "M": {
"Sensor": { "S": "Sensor7" },
"SensorDescription": { "S": "This is a description of a Sensor" }
}
},
{ "M": {
"Sensor": { "S": "Sensor8" },
"SensorDescription": { "S": "This is a description of a Sensor"}
}
},
{ "M": {
"Sensor": { "S": "Sensor9" },
"SensorDescription": { "S": "This is a description of a Sensor"}
}
},
{ "M": {
"Sensor": { "S": "Sensor10" },
"SensorDescription": { "S": "This is a description of a Sensor"}
}
},
{ "M": {
"Sensor": { "S": "Sensor11" },
"SampleRate": {"N": "11"},
"Locations": {"S": "New York, NY"}
}
},
{ "M": {
"Sensor": { "S": "Sensor12" },
"SampleRate": {"N": "12"},
"Locations": {"S": "Buffalo, NY"}
}
},
{ "M": {
"Sensor": { "S": "Sensor13" },
"SampleRate": {"N": "13"},
"Locations": {"S": "Chicago, IL"}
}
},
{ "M": {
"Sensor": { "S": "Sensor14" },
"SampleRate": {"N": "14"},
"Locations": {"S": "Trenton, NJ"}
}
},
{ "M": {
"Sensor": { "S": "Sensor15" },
"SampleRate": {"N": "15"},
"Locations": {"S": "Los Angeles, CA"}
}
},
{ "M": {
"Sensor": { "S": "Sensor16" },
"SampleRate": {"N": "16"},
"SensorDescription": { "S": "This is a description of a Sensor"},
"AltName": {"S": "Sensor-16"}
}
},
{ "M": {
"Sensor": { "S": "Sensor17" },
"SampleRate": {"N": "17"},
"SensorDescription": { "S": "This is a description of a Sensor"},
"Date": {"S": "2022-09-11 15:00:00.000"}
}
},
{ "M": {
"Sensor": { "S": "Sensor18" },
"SampleRate": {"N": "18"},
"SensorDescription": { "S": "This is a description of a Sensor"},
"Working": {"BOOL": false }
}
},
{ "M": {
"Sensor": { "S": "Sensor19" },
"SampleRate": {"N": "19"},
"SensorDescription": { "S": "This is a description of a Sensor"},
"color": {"S": "Green" }
}
},
{ "M": {
"Sensor": { "S": "Sensor20" },
"SampleRate": {"N": "20"},
"SensorDescription": { "S": "This is a description of a Sensor"},
"Senor_type": {"S": "Type 2" }
}
}
]
}
}
Here is the table:
My eyes must be playing tricks on me because I can't see the issue or am I doing something else wrong? Any help is greatly appreciated.
Apparently my description of the issue is too short so I am writing this sentence so I may post..
Upvotes: 0
Views: 967
Reputation: 19793
While the previous answer by hunterhacker is correct, put-item
cannot be used to insert batches of items. Instead, to insert a batch of items we must use batch-write-item
which will allow us insert up to 25 items per batch:
https://docs.aws.amazon.com/cli/latest/reference/dynamodb/batch-write-item.html
For your use-case, you will need to alter your JSON slightly to make it work. I have edited your example given which you can further refer to and use:
{
"Sensors": [
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor1"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
},
"ImageFile": {
"S": "/Sensors/image/Sensor1.txt"
},
"SampleRate": {
"N": "1"
},
"Locations": {
"S": "Orlando, FL"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor2"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
},
"ImageFile": {
"S": "/Sensors/image/Sensor2.txt"
},
"SampleRate": {
"N": "2"
},
"Locations": {
"S": "Annapolis, MD"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor3"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
},
"ImageFile": {
"S": "/Sensors/image/Sensor3.txt"
},
"SampleRate": {
"N": "3"
},
"Locations": {
"S": "Jacksonville, FL"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor4"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
},
"ImageFile": {
"S": "/Sensors/image/Sensor4.txt"
},
"SampleRate": {
"N": "4"
},
"Locations": {
"S": "Balitimore, MD"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor5"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
},
"ImageFile": {
"S": "/Sensors/image/Sensor5.txt"
},
"SampleRate": {
"N": "5"
},
"Locations": {
"S": "Washington DC"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor6"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor7"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor8"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor9"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor10"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor11"
},
"SampleRate": {
"N": "11"
},
"Locations": {
"S": "New York, NY"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor12"
},
"SampleRate": {
"N": "12"
},
"Locations": {
"S": "Buffalo, NY"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor13"
},
"SampleRate": {
"N": "13"
},
"Locations": {
"S": "Chicago, IL"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor14"
},
"SampleRate": {
"N": "14"
},
"Locations": {
"S": "Trenton, NJ"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor15"
},
"SampleRate": {
"N": "15"
},
"Locations": {
"S": "Los Angeles, CA"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor16"
},
"SampleRate": {
"N": "16"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
},
"AltName": {
"S": "Sensor-16"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor17"
},
"SampleRate": {
"N": "17"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
},
"Date": {
"S": "2022-09-11 15:00:00.000"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor18"
},
"SampleRate": {
"N": "18"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
},
"Working": {
"BOOL": false
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor19"
},
"SampleRate": {
"N": "19"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
},
"color": {
"S": "Green"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor20"
},
"SampleRate": {
"N": "20"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
},
"Senor_type": {
"S": "Type 2"
}
}
}
}
]
}
Now to insert this into your table, you can use the following batch-write-item
command:
aws dynamodb batch-write-item \
--request-items file://sensors.json \
--return-consumed-capacity TOTAL
Hope that helps :)
Upvotes: 1
Reputation: 7132
The put-item
call takes a singular item and you’re trying to pass a list. You can see the docs and format definition at https://docs.aws.amazon.com/cli/latest/reference/dynamodb/put-item.html
Upvotes: 0