I have been struggling with the lambda function part of the visitor counter for a bit now...and have been trying to just focus on understanding how to interact with the DynamoDB table using a lambda function. My initial step is to get the count that is stored in my table using this code. The issue I am getting is that it does not return an actual item, it just returns the metadata. I don't believe I can manipulate that to get the counter. I have seen some people use return response['Item'] , but that gives me a different error since it does not seem to like when I add the ['Item']
#[Solved] get_item() does not return an item
16 messages · Page 1 of 1 (latest)
The response status is 200 so it seems that your query ran successfully. And no Item in the response could mean that DynamoDB couldn't find any item matching your Key.
Perhaps you might want to check the key you're sending in the query or check the table directly from the console to see if your item exists.
If I do table.scan() it will return the whole table (in this case it is just the one thing) so I know that the table is in fact populated. However, that returns that whole item, not just the count which is what I need.
Since you have the items in the table, I would check if the specific Key with 'visitor_id': 'visitor_count' (as used in the get_item call) exists in the table.
How would I do that differently than the get_item(), the scan(), and just manually checking the table? (I was afraid I typed them in slightly wrong so I copied and pasted they keys from dynamoDB)
What does the response to the scan() look like?
I think I figured it out. I have been switching 'visitor_count' and 'visitor_counter'. By switching the two I now get an 'Item' and can actual retrieve the count
Yup. That's right. Your previous get_item call was querying with a non-existent value visitor_count on the visitor_id key.
visitor_count is the attribute you're interested in, i.e. the one with your number
In my opinion, perhaps this calls for a rethink on how your keys are named. Instead of visitor_id, would you consider another way to name the primary partition key? That could improve clarity in the structure of your table.
Completely agree. I obviously was very confused on how the table schema was. Originally figured it would just be the one row, and did not realize that was really just the headers of the table.
Appreciate you helping me thru this by talking it out
Glad you found the fix. Onwards! 😁
You might want to modify the post title to say it's been solved. Could be helpful for others in the future.
get_item() does not return an item (Solved)