-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_table.py
57 lines (49 loc) · 1.65 KB
/
create_table.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
AWS_DynamoDB_Solutions #kiddjsh
"""
"""
Creates an Amazon DynamoDB table that can be used to store data.
The table uses Entity as the partition key, no sort key is used.
:Python Version: Python 3.7.10
:param TableName: The name of the table to create.
:param KeySchema: Specifies the primary key for the table.
"""
# boto3 is the aws software development kit (sdk) for python
import boto3
# Gets the service resource.
DDB_RESOURCE = boto3.resource("dynamodb", region_name="us-east-1")
# Creates the DynamoDB table.
table = DDB_RESOURCE.create_table(
# The name of the table to create.
TableName="Architecture",
# Specifies the attributes that make up the primary key for a table or an index.
KeySchema=[
{
#The name of this key attribute.
"AttributeName": "Entity",
#The role that the key attribute will assume.
"KeyType": "HASH"
}
],
#An array of objects that describe one attribute and index key schema.
AttributeDefinitions=[
{
#The name of the attribute.
"AttributeName": "Entity",
#The data type for the attribute.
"AttributeType": "S"
}
],
#The setting consisting of read and write capacity units
ProvisionedThroughput={
#The maximum number of strongly consistent reads consumed per second
"ReadCapacityUnits": 10,
#The maximum number of writes consumed per second
"WriteCapacityUnits": 10
}
)
# Waits until the table exists.
table.wait_until_exists()
# Prints out some data about the table.
print(table)
print("Table created successfully!")