forked from awsdocs/aws-doc-sdk-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01-create-table.py
More file actions
47 lines (38 loc) · 1.32 KB
/
01-create-table.py
File metadata and controls
47 lines (38 loc) · 1.32 KB
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
#!/usr/bin/env python3
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
"""
Purpose
Creates an Amazon DynamoDB table to use for the demonstration.
"""
# snippet-start:[dynamodb.Python.TryDax.01-create-table]
import boto3
def create_dax_table(dyn_resource=None):
"""
Creates a DynamoDB table.
:param dyn_resource: Either a Boto3 or DAX resource.
:return: The newly created table.
"""
if dyn_resource is None:
dyn_resource = boto3.resource("dynamodb")
table_name = "TryDaxTable"
params = {
"TableName": table_name,
"KeySchema": [
{"AttributeName": "partition_key", "KeyType": "HASH"},
{"AttributeName": "sort_key", "KeyType": "RANGE"},
],
"AttributeDefinitions": [
{"AttributeName": "partition_key", "AttributeType": "N"},
{"AttributeName": "sort_key", "AttributeType": "N"},
],
"BillingMode": "PAY_PER_REQUEST",
}
table = dyn_resource.create_table(**params)
print(f"Creating {table_name}...")
table.wait_until_exists()
return table
if __name__ == "__main__":
dax_table = create_dax_table()
print(f"Created table.")
# snippet-end:[dynamodb.Python.TryDax.01-create-table]