@@ -12,20 +12,23 @@ module.exports.streambotBackup = streambot(incrementalBackup);
12
12
function replicate ( event , context , callback ) {
13
13
var replicaConfig = {
14
14
table : process . env . ReplicaTable ,
15
- region : process . env . ReplicaRegion ,
16
15
maxRetries : 1000 ,
17
16
httpOptions : {
18
17
timeout : 750 ,
19
18
agent : streambot . agent
20
19
}
21
20
} ;
21
+
22
+ if ( ! process . env . ReplicaRegion ) replicaConfig . region = event . Records [ 0 ] . awsRegion ;
22
23
if ( process . env . ReplicaEndpoint ) replicaConfig . endpoint = process . env . ReplicaEndpoint ;
24
+
23
25
var replica = new Dyno ( replicaConfig ) ;
24
26
25
- var keyAttrs = Object . keys ( event . Records [ 0 ] . dynamodb . Keys ) ;
27
+ var keyAttrs = Object . keys ( event . Records [ 0 ] . dynamodb . Keys ) ;
26
28
27
29
var allRecords = event . Records . reduce ( function ( allRecords , change ) {
28
30
var id = JSON . stringify ( change . dynamodb . Keys ) ;
31
+ id = id . replace ( '"InstanceId":{"N"' , '"InstanceId":{"S"' ) ;
29
32
allRecords [ id ] = allRecords [ id ] || [ ] ;
30
33
allRecords [ id ] . push ( change ) ;
31
34
return allRecords ;
@@ -36,11 +39,11 @@ function replicate(event, context, callback) {
36
39
var change = allRecords [ key ] . pop ( ) ;
37
40
if ( change . eventName === 'INSERT' || change . eventName === 'MODIFY' ) {
38
41
return {
39
- PutRequest : { Item : Dyno . deserialize ( JSON . stringify ( change . dynamodb . NewImage ) ) }
42
+ PutRequest : { Item : Dyno . deserialize ( JSON . stringify ( change . dynamodb . NewImage ) . replace ( '"InstanceId":{"N"' , '"InstanceId":{"S"' ) ) }
40
43
} ;
41
44
} else if ( change . eventName === 'REMOVE' ) {
42
45
return {
43
- DeleteRequest : { Key : Dyno . deserialize ( JSON . stringify ( change . dynamodb . Keys ) ) }
46
+ DeleteRequest : { Key : Dyno . deserialize ( JSON . stringify ( change . dynamodb . Keys ) . replace ( '"InstanceId":{"N"' , '"InstanceId":{"S"' ) ) }
44
47
}
45
48
}
46
49
} ) ;
0 commit comments