Created
June 1, 2021 05:44
-
-
Save dineshsonachalam/6ebed6a1cf5179ad8a72c036a570e8f4 to your computer and use it in GitHub Desktop.
Create a new table
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
from LucidDynamodb.Operations import DynamoDb | |
import os | |
import logging | |
import uuid | |
from boto3.dynamodb.conditions import Key | |
logging.basicConfig(level=logging.INFO) | |
AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID") | |
AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY") | |
table_schema = { | |
"TableName": "dev_jobs", | |
"KeySchema": [ | |
{ | |
"AttributeName": "company_name", | |
"KeyType": "HASH" | |
}, | |
{ | |
"AttributeName": "role_id", | |
"KeyType": "RANGE" | |
} | |
], | |
"AttributeDefinitions": [ | |
{ | |
"AttributeName": "company_name", | |
"AttributeType": "S" | |
}, | |
{ | |
"AttributeName": "role_id", | |
"AttributeType": "S" | |
} | |
], | |
"GlobalSecondaryIndexes": [], | |
"ProvisionedThroughput": { | |
"ReadCapacityUnits": 1, | |
"WriteCapacityUnits": 1 | |
} | |
} | |
if __name__ == "__main__": | |
db = DynamoDb(region_name="us-east-1", | |
aws_access_key_id=AWS_ACCESS_KEY_ID, | |
aws_secret_access_key=AWS_SECRET_ACCESS_KEY) | |
table_creation_status = db.create_table( | |
TableName=table_schema.get("TableName"), | |
KeySchema=table_schema.get("KeySchema"), | |
AttributeDefinitions=table_schema.get("AttributeDefinitions"), | |
GlobalSecondaryIndexes=table_schema.get("GlobalSecondaryIndexes"), | |
ProvisionedThroughput=table_schema.get("ProvisionedThroughput") | |
) | |
if(table_creation_status == True): | |
logging.info("{} table created successfully".format(table_schema.get("TableName"))) | |
else: | |
logging.error("{} table creation failed".format(table_schema.get("TableName"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment