使用pynamodb放置一个具有新属性的项目

发布于 2025-01-31 21:53:02 字数 526 浏览 3 评论 0原文

我有通过基础结构-AS代码实现创建的现有DynamoDB表。

我使用tableConnection连接到现有表并运行下级命令put_item

我的表由Hash键(userId)定义,然后对键(transActionId)定义。

我想放置一个带有其他属性的项目(timestamp符号nature)。

我没有定义这些其他属性。

当我运行以下命令时:

table = TableConnection('ExistingTable')
table.put_item(user_id, transaction_id, attributes={...})

我会收到以下错误:

value error:['userId','transactionId']中没有属性时间戳

I have existing DynamoDB tables created through an infrastructure-as-code implementation.

I used TableConnection to connect to the existing table and run the lower level command put_item.

My table is defined with a hash key (userId) and sort key (transactionId).

I want to put an item with additional attributes (timestamp, symbol, quantity).

I have not defined these additional attributes.

When I run the following command:

table = TableConnection('ExistingTable')
table.put_item(user_id, transaction_id, attributes={...})

I receive the following error:

ValueError: No attribute timestamp in ['userId', 'transactionId']

How do I put an item without defining the attributes previously?

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

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

发布评论

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

评论(1

倾听心声的旋律 2025-02-07 21:53:02

昨天我遇到了完全相同的问题,在揉了揉头几个小时后,我终于发现,使用此低级API时,我们必须使用 attributeValue 指定其他属性(包括相应的数据类型)。

因此,您可能应该写这样的东西:

table = TableConnection('ExistingTable')
table.put_item(
    user_id,
    transaction_id,
    attributes={
        "timestamp": {"N": timestamp},
        "symbol": {"S": symbol},
        "quantity": {"N": quantity},
    },
)

I encountered the exact same issue yesterday and after rubbing my head for hours, I've finally figured out that when using this low level API, we must use the format of AttributeValue to specify the additional attributes (including the corresponding data type).

So it's likely you're supposed to write something like this:

table = TableConnection('ExistingTable')
table.put_item(
    user_id,
    transaction_id,
    attributes={
        "timestamp": {"N": timestamp},
        "symbol": {"S": symbol},
        "quantity": {"N": quantity},
    },
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文