Created
April 6, 2016 16:34
-
-
Save chocksaway/f92c9a7bc12c717d8846caf6837159b5 to your computer and use it in GitHub Desktop.
Dynamo-db 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 logging | |
import boto3 | |
def create_dynamo_table(table_name, key_schema, attribute_definitions, provisioned_throughput): | |
dynamodb = boto3.resource('dynamodb', region_name='eu-west-1') | |
try: | |
dynamodb.create_table( | |
TableName=table_name, | |
KeySchema=key_schema, | |
AttributeDefinitions=attribute_definitions, | |
ProvisionedThroughput=provisioned_throughput | |
) | |
except Exception as e: | |
logging.warn("Exception in Dynamodb table creation %s", e) | |
def main(): | |
table_name = 'table001' | |
key_schema = [ | |
{ | |
"KeyType": "HASH", | |
"AttributeName": "deviceId" | |
}, | |
{ | |
"KeyType": "RANGE", | |
"AttributeName": "topicURN" | |
} | |
] | |
attribute_definitions = [ | |
{ | |
"AttributeName": "deviceId", | |
"AttributeType": "S" | |
}, | |
{ | |
"AttributeName": "topicURN", | |
"AttributeType": "S" | |
} | |
] | |
provisioned_throughput = { | |
"WriteCapacityUnits": 10, | |
"ReadCapacityUnits": 5 | |
} | |
create_dynamo_table(table_name, key_schema, attribute_definitions, provisioned_throughput) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment