22
33from __future__ import print_function # Python 2/3 compatibility
44import boto3 , random , json
5+ import argparse
56
67from boto3 .dynamodb .conditions import Key
78
89from 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
1220table = dynamodb .Table ('ExampleTable' )
1321
14- write_shard_count = 2
22+ # Use the provided shard count
23+ write_shard_count = args .shard_count
1524
1625items = [
1726 {
118127pk = "2021-02-01." + str (shard_id )
119128resp = table .query (KeyConditionExpression = Key ('pk' ).eq (pk ))
120129print ("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