Skip to content

Commit 7488125

Browse files
author
Imhoertha Ojior
committed
Update WriteShardingExample.py to accept region and shard count as parameters
1 parent 0e86c41 commit 7488125

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

schema_design/BuildingBlocks/WriteSharding/python/WriteShardingExample.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,25 @@
22

33
from __future__ import print_function # Python 2/3 compatibility
44
import boto3, random, json
5+
import argparse
56

67
from boto3.dynamodb.conditions import Key
78

89
from botocore.exceptions import ClientError
910

10-
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
11+
# Parse command line arguments
12+
parser = argparse.ArgumentParser(description='Write sharding example')
13+
parser.add_argument('--region', type=str, default='us-east-1', help='AWS region name (default: us-east-1)')
14+
parser.add_argument('--shard-count', type=int, default=2, help='Number of write shards to use (default: 2)')
15+
args = parser.parse_args()
16+
17+
# Initialize DynamoDB with the provided region
18+
dynamodb = boto3.resource('dynamodb', region_name=args.region)
1119

1220
table = dynamodb.Table('ExampleTable')
1321

14-
write_shard_count = 2
22+
# Use the provided shard count
23+
write_shard_count = args.shard_count
1524

1625
items = [
1726
{
@@ -118,4 +127,4 @@
118127
pk = "2021-02-01." + str(shard_id)
119128
resp = table.query(KeyConditionExpression=Key('pk').eq(pk))
120129
print("Data from table with calculated write shards")
121-
print(json.dumps(resp['Items'], indent=4, sort_keys=True))
130+
print(json.dumps(resp['Items'], indent=4, sort_keys=True))

0 commit comments

Comments
 (0)