1.1. The awstin.dynamodb.DynamoModel Class

1.1.1. Table Models

The elemental object for DynamoDB in awstin is not the JSON dict, but instead a awstin.dynamodb.DynamoModel subclass representing a view of the data in a table or index.

Each awstin.dynamodb.DynamoModel subclass should have a _table_name_ attribute on its class definition which is the name of the table in DynamoDB the model relates to.

The class should also have definitions of table keys and any additional attributes you want through awstin.dynamodb.Key and awstin.dynamodb.Attr definitions. By default, the attribute name on the data model is the property name in DynamoDB, but a property name can also be specified by passing in a string argument.

Below is a data model representing information for the Movies table in the AWS documentation example.

from awstin.dynamodb import Attr, DynamoModel, Key


class Movie(DynamoModel):
    _table_name_ = "Movies"

    #: Year the film  was made (hash key)
    year = Key()

    #: Title of the film (sort key)
    title = Key()

    #: Additional information about the film
    info = Attr()

1.1.2. Index Models

awstin.dynamodb.DynamoModel subclasses can also reference local or global secondary indexes. These work the same as table data models, but in addition to the _table_name_ attribute, an _index_name_ attribute should also be provided, defining the name of the index.