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_,
}
]

View File

@@ -1,10 +1,10 @@
from typing import Self
from aws_lambda_powertools.shared.json_encoder import Encoder
from aws_lambda_powertools.utilities.data_classes.dynamo_db_stream_event import (
DynamoDBRecordEventName,
)
from meilisearch import Client
from utils import JSONEncoder
class Op:
@@ -53,10 +53,3 @@ class Op:
self.op[index][op] = []
return self.op[index][op].append(data)
class JSONEncoder(Encoder):
def default(self, obj):
if isinstance(obj, set):
return list(obj)
return super(__class__, self).default(obj)

View File

@@ -1,5 +1,6 @@
import dictdiffer
from arnparse import arnparse
from aws_lambda_powertools.shared.json_encoder import Encoder
def table_from_arn(arn: str) -> str:
@@ -17,3 +18,10 @@ def diff(first: dict, second: dict) -> list[str]:
changed.append(path)
return changed
class JSONEncoder(Encoder):
def default(self, obj):
if isinstance(obj, set):
return list(obj)
return super(__class__, self).default(obj)

View File

@@ -8,7 +8,7 @@ Globals:
Architectures:
- x86_64
Layers:
- !Sub arn:aws:lambda:sa-east-1:336641857101:layer:layercake:81
- !Sub arn:aws:lambda:sa-east-1:336641857101:layer:layercake:83
Environment:
Variables:
LOG_LEVEL: DEBUG