add postgres
This commit is contained in:
@@ -16,6 +16,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
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
||||
@@ -4,9 +4,10 @@ from aws_lambda_powertools.utilities.data_classes import (
|
||||
event_source,
|
||||
)
|
||||
from aws_lambda_powertools.utilities.typing import LambdaContext
|
||||
from meilisearch import Client as Meilisearch
|
||||
|
||||
from config import MEILISEARCH_API_KEY, MEILISEARCH_HOST
|
||||
from meili import Op
|
||||
from meilisearch import Client as Meilisearch
|
||||
from utils import table_from_arn
|
||||
|
||||
logger = Logger(__name__)
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
from aws_lambda_powertools import Logger, Tracer
|
||||
from aws_lambda_powertools.utilities.data_classes import (
|
||||
DynamoDBStreamEvent,
|
||||
event_source,
|
||||
)
|
||||
from aws_lambda_powertools.utilities.typing import LambdaContext
|
||||
from config import MEILISEARCH_API_KEY, MEILISEARCH_HOST
|
||||
from layercake.strutils import md5_hash
|
||||
from meili import Op
|
||||
from meilisearch import Client as Meilisearch
|
||||
from utils import table_from_arn
|
||||
|
||||
logger = Logger(__name__)
|
||||
tracer = Tracer()
|
||||
meili_client = Meilisearch(MEILISEARCH_HOST, MEILISEARCH_API_KEY)
|
||||
|
||||
|
||||
@event_source(data_class=DynamoDBStreamEvent)
|
||||
@logger.inject_lambda_context
|
||||
@tracer.capture_lambda_handler
|
||||
def lambda_handler(event: DynamoDBStreamEvent, context: LambdaContext):
|
||||
with Op(meili_client) as op:
|
||||
for record in event.records:
|
||||
new_image = record.dynamodb.new_image # type: ignore
|
||||
index = table_from_arn(record.event_source_arn) # type: ignore
|
||||
keys = record.dynamodb.keys # type: ignore
|
||||
_id = md5_hash(str(keys))
|
||||
|
||||
op.append(
|
||||
f'_{index}_replication',
|
||||
op=record.event_name, # type: ignore
|
||||
data=({'_id': _id} | new_image) or _id,
|
||||
)
|
||||
Reference in New Issue
Block a user