0

I have a child class where I am trying to fetch the dynamo db data based on a specific key, I tried multiple variations of passing a value to the key but somehow I am getting an error on the response.

class AdGroupDetailsRepository(Repository):
    def __init__(self, client, table_name):
        super().__init__(client)
        self.table_name = table_name

    def _exec_find_by_id(self, id: str):
        logger = get_provisioner_logger()
        logger.info("Table name is %s" % self.table_name)
        dynamo_table = self.client.Table(self.table_name)
        logger.info("Connected to the dynamo table...")
        logger.info("id is %s" % id)
        item = dynamo_table.get_item(Key={'ad_group': "bigdata"})
        logger.info("fetched account: ", item['Items'])
        return AdGroupDetails(id, item['account'], item['role'])

Error:

enter image description here

I am just trying to fetch the results which is nothing but the dictionary in dynamo's case and out of that I need to fetch the specific column values.

Dynamo table schema: ad_group, account, role

I am using the dynamo resource to connect to the dynamo table. Also, I am running it via lambda functions for the APIs.

1
  • If you read the docs: "If there is no matching item, GetItem does not return any data and there will be no Item element in the response." So, it's called "Item", not "Items". It's singular. And it will be absent if the item was not found. Commented Feb 8, 2023 at 0:19

1 Answer 1

1

A get_item does not have a key of Items:

logger.info("fetched account: ", item['Items'])

I believe your code is failing on this line, causing the exception to be returned.

    item = dynamo_table.get_item(Key={'ad_group': "bigdata"})['Item']
    logger.info("fetched account: " item)
    return AdGroupDetails(id, item['account'], item['role']) 

Try CLI:

aws dynamodb get-item \
--table-name <Your Table Name> \
--key '{"ad_group":{"S":"bigdata"}}' \
--region <Table Region Here>
Sign up to request clarification or add additional context in comments.

10 Comments

Yes, also it is not fetching the records based on that key. Why is it so?
What is your partition key and sort key for your table?
ad_group is the partition key
And there is no sort key? And what is the response now that you removed Items?
I am checking it rn.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.