@@ -165,14 +165,23 @@ export const outGlobalTableExtraModify = (record) => {
165165//--------------------------------------------
166166
167167export const outTtlExpiredEvents = ( ignoreTtlExpiredEvents ) => ( record ) => {
168- const { eventName, userIdentity } = record ;
168+ const { eventName, userIdentity, dynamodb : { OldImage , ApproximateCreationDateTime } } = record ;
169169 // this is not a REMOVE event or we're not ignoring the ttl expired events anyway.
170170 if ( eventName !== 'REMOVE' || ! ignoreTtlExpiredEvents ) return true ;
171171
172- // See https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_streams_Record.html
173- // We trust dynamodb that the ttl expired if its a remove and has the ttl expiry indicating
174- // identity attributes.
175- return ! ( userIdentity ?. type === 'Service' && userIdentity ?. principalId === 'dynamodb.amazonaws.com' ) ;
172+ if ( userIdentity ) {
173+ // See https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_streams_Record.html
174+ // We trust dynamodb that the ttl expired if its a remove and has the ttl expiry indicating
175+ // identity attributes.
176+ return ! ( userIdentity ?. type === 'Service' && userIdentity ?. principalId === 'dynamodb.amazonaws.com' ) ;
177+ } else if ( OldImage . ttl ?. N ) {
178+ // If no user identity attribute is present, this may be a replicated TTL delete, but we still
179+ // want to honor it because filtering out replica region events may be disabled.
180+ const ttlSec = Number ( OldImage . ttl . N ) ;
181+ return ! ( ttlSec <= ApproximateCreationDateTime ) ;
182+ } else {
183+ return true ;
184+ }
176185} ;
177186
178187// test helper
@@ -185,6 +194,9 @@ export const toDynamodbRecords = (events, { removeUndefinedValues = true } = {})
185194 eventSource : 'aws:dynamodb' ,
186195 awsRegion : e . newImage ?. awsregion || process . env . AWS_REGION || /* istanbul ignore next */ 'us-west-2' ,
187196 dynamodb : {
197+ // TODO - Fix this in next major version bump. ApproximateCreationDateTime is meant to be in seconds, not millis.
198+ // Didn't want to fix until a major version bump to avoid compatibility issues for consumers
199+ // upgrading the lib. This should be e.timestamp / 1000
188200 ApproximateCreationDateTime : e . timestamp ,
189201 Keys : e . keys ? marshall ( e . keys , { removeUndefinedValues } ) : /* istanbul ignore next */ undefined ,
190202 NewImage : e . newImage ? marshall ( e . newImage , { removeUndefinedValues } ) : undefined ,
0 commit comments