DynamoDB 范围键超出大小限制
当我执行 table.put_item 时,我收到错误消息“所有范围键的聚合大小已超过 1024 的大小限制”。我有哪些选项可以保存我的数据?
- 更改 DynamoDB 中的设置以允许更大的限制?
- 拆分或压缩项目并保存到 DynamoDB?
- 将项目存储在 s3 中?
- 使用另一种数据库?
- 其他选择?
下面是具体的代码片段:
def put_record(item):
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('table_name')
table.put_item(Item=item)
这是存储在 DynamoDB 中的项目的示例。两个字符串变量 p 和 r 组合起来最多可以有 4000 个标记。
{
"uuid": {
"S": "5bf19498-344c"
},
“p”: {
"S": “What is the next word after Mary had a”
},
“pp”: {
"S": "0"
},
"response_length": {
"S": "632"
},
"timestamp": {
"S": "04/03/2022 06:30:55 AM CST"
},
"s": {
"S": "1"
},
"c": {
"S": "test"
},
"f": {
"S": "0"
},
"t": {
"S": "0.7"
},
"to": {
"S": "1"
},
"b": {
"S": "1"
},
"r": {
"S": “lamb”
}
}
我读了这个 https://docs.aws.amazon.com/amazondynamodb/latest/开发人员指南/ServiceQuotas.html 并且无法弄清楚 1024 是如何计算的,但我假设两个字符串变量导致了错误。
当 Item 尺寸较小时,put_item 不会导致错误;仅当大小大于 1024 限制时。
很难估计有多少保存会很大,但我需要能够保存大项目。因此,从架构角度愿意考虑任何和所有选项。
感谢您的帮助!
When I do a table.put_item I get the error message "Aggregated size of all range keys has exceeded the size limit of 1024". What options do I have so I can save my data?
- Change a setting in DynamoDB to allow a larger limit?
- Split or compress the item and save to DynamoDB?
- Store the item in s3?
- Use another kind of database?
- Other options?
Here is the specific code snippet:
def put_record(item):
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('table_name')
table.put_item(Item=item)
Here is an example of an item stored in DynamoDB. The two string variables p and r combined could be up to 4000 tokens.
{
"uuid": {
"S": "5bf19498-344c"
},
“p”: {
"S": “What is the next word after Mary had a”
},
“pp”: {
"S": "0"
},
"response_length": {
"S": "632"
},
"timestamp": {
"S": "04/03/2022 06:30:55 AM CST"
},
"s": {
"S": "1"
},
"c": {
"S": "test"
},
"f": {
"S": "0"
},
"t": {
"S": "0.7"
},
"to": {
"S": "1"
},
"b": {
"S": "1"
},
"r": {
"S": “lamb”
}
}
I read this
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ServiceQuotas.html
and couldn't figure out how the 1024 is calculated but I'm assuming the two string variables are causing the error.
The put_item doesn't cause an error when Item is a smaller size; only when the size is larger than the 1024 limit.
It is hard to estimate how many of the saves will be large but I need to be able to save the large items. So from an architecture perspective willing to consider any and all options.
Appreciate the assistance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误消息“所有范围键的聚合大小已超过 1024 的大小限制”令人费解,因为只能有一个排序键,那么“聚合”指的是什么?以下帖子也对此消息感到惊讶: https://www.stuffofminsun .com/2019/05/07/dynamodb-keys/。
我猜你实际上确实尝试编写一个项目,其中“p”(你说的是你的排序键)本身超过 1024 个字符。我不明白 p+r 组合的大小有什么影响。您可以查看(和/或包含在问题中)失败的一个特定请求,并检查 p 本身的长度是多少。另请仔细检查您是否确实将“p”而不是其他内容设置为排序键。
最后,如果您确实需要长度超过 1024 个字符的排序键,您可以考虑 Scylla Alternator - 一个与 DynamoDB 兼容的开源数据库,它没有此特定限制。
The error message "Aggregated size of all range keys has exceeded the size limit of 1024" is baffling because there can only be one sort key, so what does "aggregate" refer to? The following post was also surprised by this message: https://www.stuffofminsun.com/2019/05/07/dynamodb-keys/.
I am guessing you actually do try to write an item where its "p" (which you said is your sort key) itself is over 1024 characters. I don't see how it's the size of p+r combined that matters. You can take a look (and/or include in the question) at the one specific request that fails, and check what is the length of p itself. Please also double-check that you really set "p", and not something else, as the sort key.
Finally, if you really need sort keys over 1024 characters in length, you can consider Scylla Alternator - an open-source DynamoDB-compatible database which doesn't have this specific limitation.