fix
This commit is contained in:
@@ -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_,
|
||||
}
|
||||
]
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user