3.1. Create a New ItemΒΆ

As demonstrated in the last section, new items are added by instantiating the data model classes and passing them to awstin.dynamodb.Table.put_item().

from models import Movie

from awstin.dynamodb import DynamoDB


def put_movie(title, year, plot, rating):
    dynamodb = DynamoDB()
    table = dynamodb[Movie]

    movie = Movie(
        title=title,
        year=year,
        info={
            "plot": plot,
            "rating": rating,
        },
    )
    response = table.put_item(movie)
    return response


if __name__ == "__main__":
    movie_resp = put_movie(
        "The Big New Movie",
        2015,
        "Nothing happens at all.",
        0,
    )
    print("Put movie succeeded:")
    print(movie_resp)