Created
February 19, 2020 10:06
-
-
Save philschmid/6eb623ed2599dea4f79fbcc1f0bb7756 to your computer and use it in GitHub Desktop.
Duplicate Dynamo Table to other account/organization
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 characters
| import boto3 | |
| import os | |
| ### source aws config parameter | |
| source_aws_region='eu-west-1' | |
| source_aws_access_key_id='####' | |
| source_aws_secret_acess_key='####' | |
| source_dynamodb_table='table_name' | |
| ### target aws config parameter | |
| target_aws_region='eu-west-1' | |
| target_aws_access_key_id='####' | |
| target_aws_secret_acess_key='####' | |
| target_dynamodb_table='table_name' | |
| ### DynamoDb - Clients | |
| # | |
| # Source Client | |
| source_dynamo_client = boto3.client('dynamodb',region_name=source_aws_region, | |
| aws_access_key_id=source_aws_access_key_id, | |
| aws_secret_acess_key=source_aws_secret_acess_key | |
| ) | |
| # Target Client | |
| target_dynamo_client_source = boto3.client('dynamodb',region_name=target_aws_region, | |
| aws_access_key_id=target_aws_access_key_id, | |
| aws_secret_acess_key=target_aws_secret_acess_key | |
| ) | |
| ### Get Data | |
| source_dynamo_paginator = source_dynamo_client.get_paginator('scan') | |
| source_dyanmo_response = source_dynamo_paginator.paginate( | |
| TableName=source_dynamodb_table, | |
| Select='ALL_ATTRIBUTES', | |
| ReturnConsumedCapacity='None', | |
| ConsistentRead=True | |
| ) | |
| ### Insert Items into | |
| for page in source_dynmao_reponse: | |
| for item in page['page']: | |
| target_dynamo_client_put_item( | |
| TableName=target_dynamodb_table, | |
| Item=item | |
| ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment