diff --git a/snapshot-replicator/functions/shipper.py b/snapshot-replicator/functions/shipper.py index d7ad66d..0861186 100755 --- a/snapshot-replicator/functions/shipper.py +++ b/snapshot-replicator/functions/shipper.py @@ -2,6 +2,7 @@ import botocore import re import os +import json source_region = os.environ['SOURCE_REGION'] target_region = os.environ['TARGET_REGION'] @@ -11,12 +12,13 @@ print('Loading function') def lambda_handler(event, context): - if("Manual snapshot created" in event['Records'][0]['Sns']['Message']): + message = event['Records'][0]['Sns']['Message'] + if "Manual snapshot created" in message: source = boto3.client('rds', region_name=source_region) - source_snap = event['Records'][0]['Sns']['Source'] + source_snap = json.loads(message)['Source ID'] snapshot_details = source.describe_db_snapshots(DBSnapshotIdentifier=source_snap)['DBSnapshots'][0] - if snapshot_detailts['DBInstanceIdentifier'] in instances.split(','): - source_snap_arn = snapshot_detailts['DBSnapshotArn'] + if snapshot_details['DBInstanceIdentifier'] in instances.split(','): + source_snap_arn = snapshot_details['DBSnapshotArn'] target_snap_id = (re.sub('rds:', '', source_snap)) target = boto3.client('rds', region_name=target_region) print('Will Copy %s to %s' % (source_snap_arn, target_snap_id))