fix
This commit is contained in:
@@ -3,7 +3,6 @@ from typing import TYPE_CHECKING
|
|||||||
|
|
||||||
import boto3
|
import boto3
|
||||||
from aws_lambda_powertools import Logger, Tracer
|
from aws_lambda_powertools import Logger, Tracer
|
||||||
from aws_lambda_powertools.shared.json_encoder import Encoder
|
|
||||||
from aws_lambda_powertools.utilities.batch import (
|
from aws_lambda_powertools.utilities.batch import (
|
||||||
BatchProcessor,
|
BatchProcessor,
|
||||||
EventType,
|
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 aws_lambda_powertools.utilities.typing import LambdaContext
|
||||||
from layercake.dateutils import now, ttl
|
from layercake.dateutils import now, ttl
|
||||||
from utils import diff, table_from_arn
|
from utils import JSONEncoder, diff, table_from_arn
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from mypy_boto3_events.client import EventBridgeClient
|
from mypy_boto3_events.client import EventBridgeClient
|
||||||
@@ -39,7 +38,11 @@ def record_handler(record: DynamoDBRecord):
|
|||||||
now_ = now()
|
now_ = now()
|
||||||
|
|
||||||
# Should be EXPIRE if event is REMOVE and TTL has elapsed
|
# 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_type = 'EXPIRE'
|
||||||
|
|
||||||
detail = {
|
detail = {
|
||||||
@@ -55,7 +58,7 @@ def record_handler(record: DynamoDBRecord):
|
|||||||
'Source': record.event_source, # type: ignore
|
'Source': record.event_source, # type: ignore
|
||||||
'DetailType': detail_type,
|
'DetailType': detail_type,
|
||||||
'Resources': [table_name],
|
'Resources': [table_name],
|
||||||
'Detail': json.dumps(detail, cls=Encoder),
|
'Detail': json.dumps(detail, cls=JSONEncoder),
|
||||||
'Time': now_,
|
'Time': now_,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
from typing import Self
|
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 (
|
from aws_lambda_powertools.utilities.data_classes.dynamo_db_stream_event import (
|
||||||
DynamoDBRecordEventName,
|
DynamoDBRecordEventName,
|
||||||
)
|
)
|
||||||
from meilisearch import Client
|
from meilisearch import Client
|
||||||
|
from utils import JSONEncoder
|
||||||
|
|
||||||
|
|
||||||
class Op:
|
class Op:
|
||||||
@@ -53,10 +53,3 @@ class Op:
|
|||||||
self.op[index][op] = []
|
self.op[index][op] = []
|
||||||
|
|
||||||
return self.op[index][op].append(data)
|
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
|
import dictdiffer
|
||||||
from arnparse import arnparse
|
from arnparse import arnparse
|
||||||
|
from aws_lambda_powertools.shared.json_encoder import Encoder
|
||||||
|
|
||||||
|
|
||||||
def table_from_arn(arn: str) -> str:
|
def table_from_arn(arn: str) -> str:
|
||||||
@@ -17,3 +18,10 @@ def diff(first: dict, second: dict) -> list[str]:
|
|||||||
changed.append(path)
|
changed.append(path)
|
||||||
|
|
||||||
return changed
|
return changed
|
||||||
|
|
||||||
|
|
||||||
|
class JSONEncoder(Encoder):
|
||||||
|
def default(self, obj):
|
||||||
|
if isinstance(obj, set):
|
||||||
|
return list(obj)
|
||||||
|
return super(__class__, self).default(obj)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ Globals:
|
|||||||
Architectures:
|
Architectures:
|
||||||
- x86_64
|
- x86_64
|
||||||
Layers:
|
Layers:
|
||||||
- !Sub arn:aws:lambda:sa-east-1:336641857101:layer:layercake:81
|
- !Sub arn:aws:lambda:sa-east-1:336641857101:layer:layercake:83
|
||||||
Environment:
|
Environment:
|
||||||
Variables:
|
Variables:
|
||||||
LOG_LEVEL: DEBUG
|
LOG_LEVEL: DEBUG
|
||||||
|
|||||||
Reference in New Issue
Block a user