I am trying to run the following command
aws dynamodb put-item \
--table-name TABLENAME \
--item file://accounts.json \
--profile ACCOUNTID \
--region us-east-1
TABLENAME and ACCOUNTID aren't variables. Just scrubbing their actual names.
The json file looks like this
[
{
"accountid": {"N": "ACCOUNTID"},
"accountname": {"S": "ACCOUNTNAME"}
},
{
"accountid": {"N": "ACCOUNTID"},
"accountname": {"S": "ACCOUNTNAME"}
}
]
Account info is also scrubbed for this example
And I keep getting
Error parsing parameter '--item': Invalid JSON:
I've checked the JSON on various validators and it's showing it's correct.
I also have used the following json file
{
"accountid": {"N": "090697449863"},
"accountname": {"S": "awc-n-sf-devops"}
}
To put one item in the table and it works fine.
What am I missing in the json file putting 2 items, that causing the error?
Thanks in advance.
As if now put-item does not support inserting multiple items. You have to use batch-write-item
Below example can help you about how to use batch-write-item
in your case.
Content of accounts.json file
{
"test-table": [
{
"PutRequest": {
"Item": {
"accountid": {
"S": "100"
},
"accountname": {
"S": "ACCOUNTNAME1"
}
}
}
},
{
"PutRequest": {
"Item": {
"accountid": {
"S": "101"
},
"accountname": {
"S": "ACCOUNTNAME2"
}
}
}
}
]
}
CLI Command
aws dynamodb batch-write-item --region us-east-1 --profile ACCOUNTID --request-items file://accounts.json
It will insert all the items mentioned in the accounts.json
file.
Below is the attached image of inserted items after running the above command:
There is a way to use put-item
too to insert multiple items, but you need to iterate through all the items one by one and insert it into table(You can use any SDK). I believe it won't be an optimal solution because you would make multiple calls to the put-item
API.
The put-item feature allows you to put an item, not multiple items.
Use batch-write-item for multiple items, or call put-item
once per item.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.