File tree Expand file tree Collapse file tree 3 files changed +14
-2
lines changed Expand file tree Collapse file tree 3 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ export class DeviceStorage extends Construct {
18
18
? RemovalPolicy . DESTROY
19
19
: RemovalPolicy . RETAIN ,
20
20
pointInTimeRecovery : true ,
21
- stream : DynamoDB . StreamViewType . NEW_IMAGE ,
21
+ stream : DynamoDB . StreamViewType . NEW_AND_OLD_IMAGES ,
22
22
} )
23
23
this . devicesTable . addGlobalSecondaryIndex ( {
24
24
indexName : this . devicesTableFingerprintIndexName ,
Original file line number Diff line number Diff line change @@ -72,6 +72,7 @@ export class UpdateDevice extends Construct {
72
72
S : [ { exists : true } ] ,
73
73
} ,
74
74
} ,
75
+ OldImage : [ { exists : true } ] ,
75
76
} ,
76
77
} ) ,
77
78
] ,
Original file line number Diff line number Diff line change @@ -15,15 +15,26 @@ export const handler = middy()
15
15
. handler ( async ( event : DynamoDBStreamEvent ) : Promise < void > => {
16
16
for ( const record of event . Records ) {
17
17
const newImage = record . dynamodb ?. NewImage
18
- if ( newImage === undefined ) {
18
+ const oldImage = record . dynamodb ?. OldImage
19
+ if ( newImage === undefined || oldImage === undefined ) {
19
20
continue
20
21
}
22
+ const { hideDataBefore : oldHideDataBefore } = unmarshall (
23
+ oldImage as Record < string , AttributeValue > ,
24
+ ) as { hideDataBefore : string }
21
25
const { deviceId, hideDataBefore } = unmarshall (
22
26
newImage as Record < string , AttributeValue > ,
23
27
) as {
24
28
deviceId : string
25
29
hideDataBefore : string
26
30
}
31
+
32
+ if ( hideDataBefore === oldHideDataBefore ) {
33
+ console . log (
34
+ `No change in hideDataBefore for device ${ deviceId } , skipping...` ,
35
+ )
36
+ continue
37
+ }
27
38
console . log (
28
39
`Hiding data before ${ hideDataBefore } for device ${ deviceId } ...` ,
29
40
)
You can’t perform that action at this time.
0 commit comments