簡體   English   中英

Pynamodb - 如何設置區域?

[英]Pynamodb - how to set the region?

Python 3

下面的代碼有效但保存到us-east-1區域。 我怎么能把它保存到我們 - 西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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM