-
Notifications
You must be signed in to change notification settings - Fork 220
/
Copy pathadd_gsi.py
40 lines (36 loc) · 1.1 KB
/
add_gsi.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
from __future__ import print_function # Python 2/3 compatibility
import boto3
dynamodb = boto3.resource('dynamodb', region_name='us-west-2')
table = dynamodb.Table("RetailDatabase") # Substitute your table name for RetailDatabase
table.update(
AttributeDefinitions=[
{
'AttributeName': 'status',
'AttributeType': 'S'
},
{
'AttributeName': 'GSI2-SK',
'AttributeType': 'S'
},
],
GlobalSecondaryIndexUpdates=[
{
'Create': {
'IndexName': 'VendorOrdersByStatusDate-ProductInventor',
'KeySchema': [
{
'AttributeName': 'status',
'KeyType': 'HASH' # could be 'HASH'|'RANGE'
},
{
'AttributeName': 'GSI2-SK',
'KeyType': 'RANGE' # could be 'HASH'|'RANGE'
},
],
'Projection': {
'ProjectionType': 'KEYS_ONLY', # could be 'ALL'|'KEYS_ONLY'|'INCLUDE'
},
},
},
],
)