Use AWS CLI and JSON to Load Multiple Items into DynamoDB

Search for a command to run...

No comments yet. Be the first to comment.
A quick cheatsheet for TMUX commands that I can never remember. tmux yum -y install tmux Out of tmux new session tmux new new session with name tmux new -s sessionname show sessions tmux ls attach to session tmux attach-session -t 0 Go to last sessi...
Here's a fun error: "not syncing vfs unable to mount root fs on unknown block" I'm running CentOS7 on Linode and happened to run into this error on one of my systems. Quite unusual, so I did the quick and dirty method and restored a backup of my VM....
I discovered a fun git command that I wasn't aware of before. git switch -c <new-branch> Using git switch, you can take existing, uncommitted files and move them to a new branch. Say you're working in the master branch and want to move those changes...
Well, maybe not so hidden, but definitely not advertised. Vudu has an API that, for the life of me, I could not find advertised anywhere, even with an advanced Google search. So, I'll take it upon myself to scrape their webpage and dissect their ho...
I didn't realize until recently that you can run DynamoDB on a local machine on either Windows, Mac, or Linux. This obviously can be hugely benefitial for learning and dabbling in DynamoDB, without racking up a large AWS bill. Let's see if we can get...
I found it surprisingly difficult to find documentation that demonstrates how to add MULTIPLE items to a dynamo DB from a single JSON file. Well here is it, plain and simple. I've included a few different types of examples.
Here's the template:
{
"DDBTableName":[
{
"PutRequest":{
"Item":{
"keyName":{"DataType":"Value1"}
}
}
},
{
"PutRequest":{
"Item":{
"keyName":{"DataType":"Value2"}
}
}
}
]
}
Here's a sample table called HotelInfoAccessibility. It has a single key called "text". Real fancy, I know.
{
"HotelInfoAccessibility": [
{
"PutRequest": {
"Item": {
"text": { "S": "Grab bars on tub walls"}
}
}
},
{
"PutRequest": {
"Item": {
"text": { "S": "Shower chairs"}
}
}
},
{
"PutRequest": {
"Item": {
"text": { "S": "Telephones with volume control"}
}
}
}
]
}
If you copy and paste to quickly fill in another table, DON'T FORGET TO CHANGE THE TABLE NAME. I did it... it wasn't fun.
This next example is also simple. It's a two key table called MenuLinks. The primary key is href, the sort key is text. I also include a class key cause that's probably a thing I need.
{
"MenuLinks": [
{
"PutRequest": {
"Item": {
"class": {
"S": "info"
},
"href": {
"S": "#hotelinfo"
},
"text": {
"S": "info"
}
}
}
},
{
"PutRequest": {
"Item": {
"class": {
"S": "rooms"
},
"href": {
"S": "#rooms"
},
"text": {
"S": "rooms"
}
}
}
},
{
"PutRequest": {
"Item": {
"class": {
"S": "dining"
},
"href": {
"S": "#dining"
},
"text": {
"S": "dining"
}
}
}
},
{
"PutRequest": {
"Item": {
"class": {
"S": "events"
},
"href": {
"S": "#events"
},
"text": {
"S": "events"
}
}
}
},
{
"PutRequest": {
"Item": {
"class": {
"S": "attractions"
},
"href": {
"S": "#attractions"
},
"text": {
"S": "attractions"
}
}
}
}
]
}
And if you want to get super fancy, you can nest your json, should work the same way.
Once you've got your data properly formatted and saved to a json file, you can run the aws cli to write these items to the table.
aws dynamodb batch-write-item --request-items file://menu_links.json
Make sure you point to the correct file location, obviously. The response will be:
{
"UnprocessedItems": {}
}
Login to the DynamoDB console, or use the cli or another program to query your data.

That's what I've been working on today. Some days are more productive than other :)
-AJ