Last active
June 20, 2021 10:27
-
-
Save Dineshkarthik/d0944c45b06726a327a9536a33dabdd2 to your computer and use it in GitHub Desktop.
Revisions
-
Dineshkarthik revised this gist
Jun 21, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -40,8 +40,8 @@ def replicate(table_name, existing_region, new_region, new_table_name): KeySchema=existing_table.key_schema, AttributeDefinitions=existing_table.attribute_definitions, ProvisionedThroughput={ 'ReadCapacityUnits': 5, 'WriteCapacityUnits': 5 }) print("Table status:", table.table_status) -
Dineshkarthik revised this gist
Jun 21, 2018 . 1 changed file with 1 addition and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -52,11 +52,7 @@ def replicate(table_name, existing_region, new_region, new_table_name): print("Updating table with data...") if table.table_status == 'ACTIVE': for item in items: response = table.put_item(Item=item) print("PutItem status:", response['ResponseMetadata']['HTTPStatusCode']) -
Dineshkarthik revised this gist
Jun 21, 2018 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,6 @@ # Copyright (C) 2018 Dineshkarthik Raveendran from __future__ import print_function # Python 2/3 compatibility import boto3 import argparse -
Dineshkarthik revised this gist
Jun 21, 2018 . 1 changed file with 4 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -41,15 +41,14 @@ def replicate(table_name, existing_region, new_region, new_table_name): KeySchema=existing_table.key_schema, AttributeDefinitions=existing_table.attribute_definitions, ProvisionedThroughput={ 'ReadCapacityUnits': 1, 'WriteCapacityUnits': 1 }) print("Table status:", table.table_status) table.wait_until_exists() table.reload() print("Table status:", table.table_status) print("Updating table with data...") if table.table_status == 'ACTIVE': -
Dineshkarthik revised this gist
Jun 20, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -41,8 +41,8 @@ def replicate(table_name, existing_region, new_region, new_table_name): KeySchema=existing_table.key_schema, AttributeDefinitions=existing_table.attribute_definitions, ProvisionedThroughput={ 'ReadCapacityUnits': 5, 'WriteCapacityUnits': 5 }) print("Table status:", table.table_status) -
Dineshkarthik revised this gist
Jun 20, 2018 . No changes.There are no files selected for viewing
-
Dineshkarthik revised this gist
Jun 20, 2018 . No changes.There are no files selected for viewing
-
Dineshkarthik created this gist
Jun 20, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,98 @@ # Copyright (C) 2018 Dineshkarthik Raveendran from __future__ import print_function # Python 2/3 compatibility import time import boto3 import argparse def replicate(table_name, existing_region, new_region, new_table_name): """ Replicate table in new region. Creates a new table with existing KeySchema and AttributeDefinitions read and write capacity untis are set to 5. Change it as required. Parameters ---------- table_name: string Name of the existing table to be replicated. existing_region: string Region in which the table is present. new_region: string Region in which the table needs to be replicated. new_table_name: string Name for the new table to be created, if not given existing table name is used. """ existing_table = boto3.resource( 'dynamodb', region_name=existing_region).Table(table_name) items = existing_table.scan()['Items'] dynamodb = boto3.resource('dynamodb', region_name=new_region) print("Creating table '{0}' in region '{1}'".format( new_table_name, new_region)) table = dynamodb.create_table( TableName=new_table_name, KeySchema=existing_table.key_schema, AttributeDefinitions=existing_table.attribute_definitions, ProvisionedThroughput={ 'ReadCapacityUnits': 1, 'WriteCapacityUnits': 1 }) print("Table status:", table.table_status) # It take 10 - 15 seconds for the table to be created time.sleep(15) table = dynamodb.Table(new_table_name) print("Table status:", table.table_status) print("Updating table with data...") if table.table_status == 'ACTIVE': for item in items: response = table.put_item(Item={ 'key': item['key'], 'value': item['value'] }) print("PutItem status:", response['ResponseMetadata']['HTTPStatusCode']) print("Total items created:", table.scan()['Count']) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument( '-t', '--table_name', type=str, required=True, help="Name of the table to be replicated in new region") parser.add_argument( '-r', '--region', type=str, required=True, help="Region in which the table is present") parser.add_argument( '-nr', '--new_region', type=str, required=True, help="Region in which the table needs to be replicated") parser.add_argument( '-nt', '--new_table_name', type=str, help="Name for the new table [Optional], Old table name will be used") args = parser.parse_args() if args.new_table_name is None: args.new_table_name = args.table_name replicate(args.table_name, args.region, args.new_region, args.new_table_name)