This commit is contained in:
2025-07-14 12:24:22 -03:00
parent 98cd751ed9
commit cfffcb2070
4 changed files with 17 additions and 13 deletions

View File

@@ -3,7 +3,6 @@ from typing import TYPE_CHECKING
import boto3
from aws_lambda_powertools import Logger, Tracer
from aws_lambda_powertools.shared.json_encoder import Encoder
from aws_lambda_powertools.utilities.batch import (
BatchProcessor,
EventType,
@@ -15,7 +14,7 @@ from aws_lambda_powertools.utilities.data_classes.dynamo_db_stream_event import
)
from aws_lambda_powertools.utilities.typing import LambdaContext
from layercake.dateutils import now, ttl
from utils import diff, table_from_arn
from utils import JSONEncoder, diff, table_from_arn
if TYPE_CHECKING:
from mypy_boto3_events.client import EventBridgeClient
@@ -39,7 +38,11 @@ def record_handler(record: DynamoDBRecord):
now_ = now()
# Should be EXPIRE if event is REMOVE and TTL has elapsed
if record.event_name is DynamoDBRecordEventName.REMOVE and ttl() >= record_ttl:
if (
record.event_name is DynamoDBRecordEventName.REMOVE
and record_ttl
and ttl() >= record_ttl
):
detail_type = 'EXPIRE'
detail = {
@@ -55,7 +58,7 @@ def record_handler(record: DynamoDBRecord):
'Source': record.event_source, # type: ignore
'DetailType': detail_type,
'Resources': [table_name],
'Detail': json.dumps(detail, cls=Encoder),
'Detail': json.dumps(detail, cls=JSONEncoder),
'Time': now_,
}
]