使用Python从DynamoDB中检索数据

发布于 2025-02-06 09:58:22 字数 513 浏览 0 评论 0原文

一般而言,DynamoDB和Python的新手。我有一项任务可以完成我必须使用一些信息从DynamoDB中检索信息的地方。我已经设置了访问密钥等等,并且得到了一个“哈希键”和一个表名。我正在寻找一种使用哈希密钥来检索信息的方法,但是我无法在线找到特定的东西。

#Table Name
table_name = 'Waypoints'

    #Dynamodb client
    dynamodb_client = boto3.client('dynamodb')
    
    #Hash key
    hash_key = {
        ''
    }
    #Retrieve items
    response = dynamodb_client.get_item(TableName = table_name, Key = hash_key)

上面是我写过的,但不起作用。获取物品仅从我可以收集的内容中返回One_item,但我不确定要传递什么以使其首先发挥作用。

任何形式的帮助都将得到极大的认可。

A newbie to DynamoDb and python in general here. I have a task to complete where I have to retrieve information from a DynamoDB using some information provided. I've set up the access keys and such and I've been provided a 'Hash Key' and a table name. I'm looking for a way to use the hash key in order to retrieve the information but I haven't been able to find something specific online.

#Table Name
table_name = 'Waypoints'

    #Dynamodb client
    dynamodb_client = boto3.client('dynamodb')
    
    #Hash key
    hash_key = {
        ''
    }
    #Retrieve items
    response = dynamodb_client.get_item(TableName = table_name, Key = hash_key)

Above is what I have writtenbut that doesn't work. Get item only returns one_item from what I can gather but I'm not sure what to pass on to make it work in the first place.

Any sort of help would be greatly appreaciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回首观望 2025-02-13 09:58:22

首先,在get_item()请求中,密钥不仅是密钥的值,而应是带有密钥名称和值的地图。例如,如果您的hash-key属性称为“ p”,则您应该通过的是{'p':hash_key}

其次,哈希键是桌子中的整个键吗?如果您也有一个排序键,则在get_item()中,还必须指定键的部分 - 结果是一个项目。如果您正在寻找具有特定哈希键但类别键的所有项目,则需要使用的功能是query(),而不是get_item()

First of all, in get_item() request the key should not be just the key's value, but rather a map with the key's name and value. For example, if your hash-key attribute is called "p", the Key you should pass would be {'p': hash_key}.

Second, is the hash key the entire key in your table? If you also have a sort key, in a get_item() you must also specify that part of the key - and the result is one item. If you are looking for all the items with a particular hash key but different sort keys, then the function you need to use is query(), not get_item().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文