Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chocksaway/f92c9a7bc12c717d8846caf6837159b5 to your computer and use it in GitHub Desktop.
Save chocksaway/f92c9a7bc12c717d8846caf6837159b5 to your computer and use it in GitHub Desktop.
Dynamo-db create table
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