Last active
June 12, 2024 12:22
-
-
Save armicron/19b88aa15838f2688bc86f60ba2f85b5 to your computer and use it in GitHub Desktop.
boto3 dynamodb, create table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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