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 {
1818 ? RemovalPolicy . DESTROY
1919 : RemovalPolicy . RETAIN ,
2020 pointInTimeRecovery : true ,
21- stream : DynamoDB . StreamViewType . NEW_IMAGE ,
21+ stream : DynamoDB . StreamViewType . NEW_AND_OLD_IMAGES ,
2222 } )
2323 this . devicesTable . addGlobalSecondaryIndex ( {
2424 indexName : this . devicesTableFingerprintIndexName ,
Original file line number Diff line number Diff line change @@ -72,6 +72,7 @@ export class UpdateDevice extends Construct {
7272 S : [ { exists : true } ] ,
7373 } ,
7474 } ,
75+ OldImage : [ { exists : true } ] ,
7576 } ,
7677 } ) ,
7778 ] ,
Original file line number Diff line number Diff line change @@ -15,15 +15,26 @@ export const handler = middy()
1515 . handler ( async ( event : DynamoDBStreamEvent ) : Promise < void > => {
1616 for ( const record of event . Records ) {
1717 const newImage = record . dynamodb ?. NewImage
18- if ( newImage === undefined ) {
18+ const oldImage = record . dynamodb ?. OldImage
19+ if ( newImage === undefined || oldImage === undefined ) {
1920 continue
2021 }
22+ const { hideDataBefore : oldHideDataBefore } = unmarshall (
23+ oldImage as Record < string , AttributeValue > ,
24+ ) as { hideDataBefore : string }
2125 const { deviceId, hideDataBefore } = unmarshall (
2226 newImage as Record < string , AttributeValue > ,
2327 ) as {
2428 deviceId : string
2529 hideDataBefore : string
2630 }
31+
32+ if ( hideDataBefore === oldHideDataBefore ) {
33+ console . log (
34+ `No change in hideDataBefore for device ${ deviceId } , skipping...` ,
35+ )
36+ continue
37+ }
2738 console . log (
2839 `Hiding data before ${ hideDataBefore } for device ${ deviceId } ...` ,
2940 )
You can’t perform that action at this time.
0 commit comments