In this step, we create a table named Movies. The primary key for the table includes the following attributes:
year – The partition key. AttributeType is N(number).
title – The sort key. AttributeType is S(string).
Create a file named MoviesCreateTable.py
Copy the following code and paste it into the file MoviesCreateTable.py
import boto3
def create_movie_table(dynamodb=None):
dynamodb = boto3.resource('dynamodb')
table = dynamodb.create_table(
TableName='Movies',
KeySchema=[
{
'AttributeName': 'year',
'KeyType': 'HASH' # Partition key
},
{
'AttributeName': 'title',
'KeyType': 'RANGE' # Sort key
}
],
AttributeDefinitions=[
{
'AttributeName': 'year',
'AttributeType': 'N'
},
{
'AttributeName': 'title',
'AttributeType': 'S'
},
],
ProvisionedThroughput={
'ReadCapacityUnits': 10,
'WriteCapacityUnits': 10
}
)
return table
if __name__ == '__main__':
movie_table = create_movie_table()
print("Table status:", movie_table.table_status)
python MoviesCreateTable.py
Another case: use python "MoviesCreateTable.py file path"
Table status: CREATING
is returned to the successful creation of the table.