gpt4 book ai didi

python-3.x - Pynamodb - 如何设置区域?

转载 作者:行者123 更新时间:2023-12-05 01:47:39 26 4
gpt4 key购买 nike

python 3

下面的代码有效,但保存到 us-east-1 区域。我如何将其保存到 us-west-1?我已经挖掘了 Pynamodb 的源代码,但没有找到正确的方法。

from pynamodb.models import Model
from pynamodb.indexes import GlobalSecondaryIndex, AllProjection
from pynamodb.attributes import UnicodeAttribute, NumberAttribute

class DaysIndex(GlobalSecondaryIndex):
"""
This class represents a global secondary index
"""
read_capacity_units = 2
write_capacity_units = 1
projection = AllProjection()
days_old = NumberAttribute(hash_key=True)


class HackerNewsLinks(Model):
"""
A test model that uses a global secondary index
"""
table_name = 'HackerNews'
link = UnicodeAttribute(hash_key=True)
title = UnicodeAttribute()
days_index = DaysIndex()
days_old = NumberAttribute(default=0)

if not HackerNewsLinks.exists():
HackerNewsLinks.create_table(read_capacity_units=1, write_capacity_units=1, region='us-west-1')

hn_item = HackerNewsLinks('http://www.blah.com', title='forum_subject', days_old=10)
hn_item.save()

# Indexes can be queried easily using the index's hash key
for item in HackerNewsLinks.days_index.query(1):
print("Item queried from index: {0}".format(item))

最佳答案

我刚刚在 0.1.12 版中为 PynamoDB 模型 API 添加了区域支持,您介意升级并重试吗?

语法如下:

class HackerNewsLinks(Model):
"""
A test model that uses a global secondary index
"""
class Meta:
region = 'us-west-1'
table_name = 'HackerNews'
link = UnicodeAttribute(hash_key=True)
title = UnicodeAttribute()
days_index = DaysIndex()
days_old = NumberAttribute(default=0)

关于python-3.x - Pynamodb - 如何设置区域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22471423/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com