1

我在 AWS dynamodb 中创建了一个全局二级索引,其中在我将手机用作 GSI 的用户表中。我收到一条消息错误:

'Table UsersTable 没有索引:PHONE_INDEX'

下面是作为 GSI 的用户表和电话的代码片段。我无法弄清楚我收到此错误的原因。

from pynamodb.models import Model
from pynamodb.indexes import GlobalSecondaryIndex, KeysOnlyProjection, AllProjection
from pynamodb.attributes import( UnicodeAttribute, NumberAttribute)
from passlib.hash import pbkdf2_sha256 as sha256
import auth.exceptions as exception

class PhoneIndex(GlobalSecondaryIndex):
    
    class Meta:
        index_name = 'PHONE_INDEX'
        read_capacity_units = 2
        write_capacity_units = 2
        # All attributes are projected
        projection = KeysOnlyProjection()

    # This attribute is the hash key for the index
    # Note that this attribute must also exist
    # in the model
    phone = UnicodeAttribute(hash_key=True)


class UserModel(Model):
    # Table Users
    if config.IS_OFFLINE:
        class Meta:
            table_name = config.USERS_TABLE
            index_name = 'PHONE_INDEX'
            host = "http://localhost:8000"
            region = config.REGION
            aws_access_key_id = 'my_access_key_id'
            aws_secret_access_key = 'my_secret_access_key'
            aws_session_token = 'my_session_token'
    else:
        class Meta:
            table_name = config.USERS_TABLE
            region = config.REGION
    customerid= UnicodeAttribute()
    phone = UnicodeAttribute()
    name = UnicodeAttribute()
    username = UnicodeAttribute(hash_key=True)
    password= UnicodeAttribute()
    phone_index=PhoneIndex()
4

1 回答 1

0

我收到此错误,因为我没有在我的 cloudformation 模板文件中添加全局二级索引。

于 2020-07-24T13:40:15.270 回答