Last active
December 27, 2021 05:25
-
-
Save agusrichard/d196890d43786ab1a32e678880e6d3e1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
def generate_table(ddb): | |
ddb = boto3.resource('dynamodb', | |
endpoint_url='http://localhost:8000', | |
region_name='example', # note that if you create a table using different region name and aws key | |
aws_access_key_id='example', # you won't see this table on the admin app | |
aws_secret_access_key='example') | |
ddb.create_table( | |
TableName='Recipes', # create table Recipes | |
AttributeDefinitions=[ | |
{ | |
'AttributeName': 'uid', # In this case, I only specified uid as partition key (there is no sort key) | |
'AttributeType': 'S' # with type string | |
} | |
], | |
KeySchema=[ | |
{ | |
'AttributeName': 'uid', # attribute uid serves as partition key | |
'KeyType': 'HASH' | |
} | |
], | |
ProvisionedThroughput={ # specying read and write capacity units | |
'ReadCapacityUnits': 10, # these two values really depend on the app's traffic | |
'WriteCapacityUnits': 10 | |
} | |
) | |
print('Successfully created table Recipes') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment