This is to demonstrate how to use DynamoDB stream with Lambda to synchronize data change between China region & Global region which were isolated with no Global Table support. This is for demo purpose only, you should consider using SQS to decouple from the Lambda to DynamoDB.
For the target site, your AK/SK should have privilege to write to target DynamoDB table.
You may have to use --profile to distinguish different accounts for China & Global region.
aws dynamodb create-table \
--table-name MusicCollection \
--attribute-definitions AttributeName=Artist,AttributeType=S AttributeName=SongTitle,AttributeType=S \
--key-schema AttributeName=Artist,KeyType=HASH AttributeName=SongTitle,KeyType=RANGE \
--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5aws dynamodb update-table --table-name MusicCollection \
--stream-specification "StreamEnabled=True,StreamViewType=NEW_IMAGE"aws dynamodb create-table \
--table-name MusicCollection \
--attribute-definitions AttributeName=Artist,AttributeType=S AttributeName=SongTitle,AttributeType=S \
--key-schema AttributeName=Artist,KeyType=HASH AttributeName=SongTitle,KeyType=RANGE \
--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5aws ssm put-parameter --name "target_ak" --value "<TARGET_ACCOUNT_AK>" --type SecureString
aws ssm put-parameter --name "target_sk" --value "<TARGET_ACCOUNT_SK>" --type SecureStringWith Managed Priviliege AWSLambdaBasicExecutionRole, AmazonSSMReadOnlyAccess, and take down its ARN
zip function.zip index.pyaws lambda create-function --function-name ddb-lambda-sync \
--zip-file fileb://function.zip --handler index.handler --runtime python3.7 \
--role <YOUR_ROLE_FOR_LAMBDA_FUNCTION>aws lambda publish-version --function-name "ddb-lambda-sync"aws lambda create-event-source-mapping \
--function-name ddb-lambda-sync \
--event-source-arn <ARN_OF_YOUR_DYNAMODB_STREAM> --starting-position LATESTaws dynamodb put-item \
--table-name MusicCollection \
--item file://item.jsonaws dynamodb get-item \
--table-name MusicCollection \
--key file://key.json --profile zhyDo not support migrating existing data in the table, only new changed data.
CDK + SQS
This library is licensed under the MIT-0 License. See the LICENSE file.
