Skip to content

Instantly share code, notes, and snippets.

@armicron
Last active October 24, 2019 06:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save armicron/19b88aa15838f2688bc86f60ba2f85b5 to your computer and use it in GitHub Desktop.
Save armicron/19b88aa15838f2688bc86f60ba2f85b5 to your computer and use it in GitHub Desktop.
boto3 dynamodb, create table
import boto3
"""
very slow
docker run -d -p 8000:8000 deangiberson/aws-dynamodb-local
very fast
docker run -d -p 8000:8000 dwmkerr/dynamodb -inMemory
"""
table_wcu = 2000
table_rcu = 2000
index_wcu = 3000
index_rcu = 2000
table_name = 'localtable'
dynamodb = boto3.resource('dynamodb', endpoint_url="http://127.0.0.1:8000")
dynamodb.create_table(TableName=table_name, KeySchema=[{'AttributeName': '_id', 'KeyType': 'HASH'}],
ProvisionedThroughput={'ReadCapacityUnits': table_rcu, 'WriteCapacityUnits': table_wcu},
AttributeDefinitions=[{'AttributeName': '_id', 'AttributeType': 'S'},
{u'AttributeName': u'city', u'AttributeType': u'S'},
{u'AttributeName': u'email', u'AttributeType': u'S'},
{u'AttributeName': u'name', u'AttributeType': u'S'},
{u'AttributeName': u'slug', u'AttributeType': u'S'}],
GlobalSecondaryIndexes=[
{'IndexName': 'city-index', 'Projection': {'ProjectionType': 'ALL'},
'ProvisionedThroughput': {'WriteCapacityUnits': index_wcu,
'ReadCapacityUnits': index_rcu},
'KeySchema': [{'KeyType': 'HASH', 'AttributeName': 'city'}]},
{'IndexName': 'name-index', 'Projection': {'ProjectionType': 'ALL'},
'ProvisionedThroughput': {'WriteCapacityUnits': index_wcu,
'ReadCapacityUnits': index_rcu},
'KeySchema': [{'KeyType': 'HASH', 'AttributeName': 'name'}]},
{'IndexName': 'slug-index', 'Projection': {'ProjectionType': 'ALL'},
'ProvisionedThroughput': {'WriteCapacityUnits': index_wcu,
'ReadCapacityUnits': index_rcu},
'KeySchema': [{'KeyType': 'HASH', 'AttributeName': 'slug'}]},
{'IndexName': 'email-index', 'Projection': {'ProjectionType': 'ALL'},
'ProvisionedThroughput': {'WriteCapacityUnits': index_wcu,
'ReadCapacityUnits': index_rcu},
'KeySchema': [{'KeyType': 'HASH', 'AttributeName': 'email'}]}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment