#[Solved] get_item() does not return an item

16 messages · Page 1 of 1 (latest)

cerulean sapphire
#

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']

broken fractal
#

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.

cerulean sapphire
broken fractal
#

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.

cerulean sapphire
broken fractal
#

What does the response to the scan() look like?

cerulean sapphire
cerulean sapphire
broken fractal
#

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.

cerulean sapphire
#

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

broken fractal
#

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.

cerulean sapphire
#

get_item() does not return an item (Solved)