last day (15 days later) » 

2:57 PM
0
Q: DynamoDB Cannot insert anything but Key

sannaI am experimenting with DynamoDB to insert some data in a table test-table. With postman and Lambda, I am trying to insert some values. Currently, my table has a Key called node, and if I try to insert a new record doing the following in the body works: { "TableName": "test-table", ...

 
Try { "TableName": "test-table", "Item": { "note": { "S": "test node"}, "title": { "S": "fred" }}}
 
@jarmod, unluckily it doesn't work as well, it only saves the key, nothing else.
 
It doesn't make sense that both your original and my variant would store the key attribute successfully, because your key is under "Key" and mine is under "Item". So, you haven't shared some key piece of information. You mentioned Postman and Lambda. How are they connected? Are you using API Gateway in front of Lambda and having Postman make API requests against API Gateway? If so, then you should show your Lambda code.
 
@jarmod, I noticed it and changed from "Item" to "Key". Anyway, I've updated the question with the Lambda code!
 
With the document client, you would put { "TableName": "test-table", "Item": { "note": "test node", "title": "fred" }}
 
2:57 PM
Thanks, but unluckily i'm getting this error: "The provided key element does not match the schema". Of course, I changed from Item to Key.
Hi! Thanks for helping
 
You can't change "Item" to "Key". The specification, if you read it, is for the params object to have 'TableName' and 'Item' attributes. What does your key schema require? Is it partition key only named 'note'? And is that a string?
 
Ok, I understand, but if i use "Item"i'm getting this: { "TableName": "test-table", "Item": { "note": "test node", "title": "fred" }}
My db instance is as follows:
Table name test-table
Primary partition key note (String)
so "note" is a key
 
So it has no range key. OK, what happens if you put that object I suggested (and do this explicitly in code, don't use the event body parsing for now)?
`const params = { "TableName": "test-table", "Item": { "note": "test node", "title": "fred" }};
await dynamo.put(params).promise();`
 
trying
then it works!
So I guess there is something wrong in parsing arguments...
 
Good, now you can backtrack and work out where the body send or body parsing error is.
 
3:07 PM
thanks a lot
I could have tried before actually...
 
BTW your app has potential for hacking abuse. You're allowing the client to dictate which DynamoDB table to write to or delete from. This is an example of the Confused Deputy problem. They could hack in a different table name and destroy other tables. So, be sure your Lambda IAM role is locked down to the minimal set of DynamoDB tables.
Or don't allow them to indicate the table name. Unless it's just a test app you're writing for fun.
I'll write up an answer. Good luck with the rest of the project.
 
Thanks! I'm just testing now, but I have an API key to protect the endpoint. I'll take into consideration what you said for production purposes
 

last day (15 days later) »