-
-
Save toastdriven/050aacbed2bcf875fb1f to your computer and use it in GitHub Desktop.
This file contains 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
import time | |
import boto.dynamodb2 | |
ddb2_conn = boto.dynamodb2.connect_to_region('us-west-2') | |
# Create the table. | |
resp = ddb2_conn.create_table( | |
table_name='test-gsi', | |
attribute_definitions=[ | |
{ | |
"AttributeName": "ForumName", | |
"AttributeType": "S" | |
}, | |
{ | |
"AttributeName": "Subject", | |
"AttributeType": "S" | |
} | |
], | |
key_schema=[ | |
{ | |
"AttributeName": "ForumName", | |
"KeyType": "HASH" | |
}, | |
{ | |
"AttributeName": "Subject", | |
"KeyType": "RANGE" | |
} | |
], | |
global_secondary_indexes=[ | |
{ | |
"IndexName": "Whatever", | |
"KeySchema": [ | |
{ | |
"AttributeName": "ForumName", | |
"KeyType": "HASH" | |
}, | |
{ | |
"AttributeName": "Subject", | |
"KeyType": "RANGE" | |
} | |
], | |
"Projection": { | |
"ProjectionType": "ALL" | |
}, | |
"ProvisionedThroughput": { | |
"ReadCapacityUnits": 3, | |
"WriteCapacityUnits": 3 | |
} | |
} | |
], | |
provisioned_throughput={ | |
"ReadCapacityUnits": 5, | |
"WriteCapacityUnits": 5 | |
} | |
) | |
assert resp.get('TableDescription', {}).get('TableStatus') == 'CREATING' | |
# Wait for the table to be ready. | |
time.sleep(60) | |
# Update the throughput. | |
resp = ddb2_conn.update_table( | |
table_name='test-gsi', | |
global_secondary_index_updates=[ | |
{ | |
"Update": { | |
"IndexName": "Whatever", | |
"ProvisionedThroughput": { | |
"ReadCapacityUnits": 1, | |
"WriteCapacityUnits": 1 | |
} | |
} | |
} | |
] | |
) | |
# Wait again. | |
time.sleep(60) | |
resp = ddb2_conn.describe_table('test-gsi') | |
gsi_info = resp.get('Table', {}).get('GlobalSecondaryIndexes', []) | |
assert len(gsi_info) > 0 | |
assert gsi_info[0]['ProvisionedThroughput']['ReadCapacityUnits'] == 1 | |
# Cleanup. | |
ddb2_conn.delete_table('test-gsi') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment