DPC — Create Table

def create_Stocks_table(dynamodb=None):
result = 'not created'
if not dynamodb:
dynamodb = boto3.client('dynamodb', endpoint_url="http://localhost:8000")

try:
table = dynamodb.create_table(
TableName='Stocks',
KeySchema=[
{
'AttributeName': 'Symbol',
'KeyType': 'HASH'
},
{
'AttributeName': 'Date',
'KeyType': 'RANGE'
}
],
AttributeDefinitions=[
{
'AttributeName': 'Symbol',
'AttributeType': 'S'
},
{
'AttributeName': 'Date',
'AttributeType': 'S'
}
],
ProvisionedThroughput={
'ReadCapacityUnits': 10,
'WriteCapacityUnits': 10
},
)
result = 'created'
print('Stocks table created')
except dynamodb.exceptions.ResourceInUseException:
print('Stocks table exists, not creating again')
result = 'Not created'
pass
return result

For Details: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.Python.01.html

--

--