move seeds dir

This commit is contained in:
2025-04-03 21:08:59 -03:00
parent 34085af4a8
commit 1358088a48
41 changed files with 1950 additions and 108 deletions

View File

View File

@@ -0,0 +1,37 @@
import meilisearch
from arnparse import arnparse
from aws_lambda_powertools.utilities.data_classes import (
DynamoDBStreamEvent,
event_source,
)
from aws_lambda_powertools.utilities.typing import LambdaContext
from settings import MEILISEARCH_API_KEY, MEILISEARCH_HOST
meili_client = meilisearch.Client(MEILISEARCH_HOST, MEILISEARCH_API_KEY)
@event_source(data_class=DynamoDBStreamEvent)
def lambda_handler(event: DynamoDBStreamEvent, context: LambdaContext):
for record in event.records:
pk = record.dynamodb.keys['id'] # type: ignore
new_image = record.dynamodb.new_image # type: ignore
index_name = table_from_arn(record.event_source_arn) # type: ignore
print(index_name, pk, record.event_name, new_image)
# match record.event_name:
# case DynamoDBRecordEventName.MODIFY:
# update_docs.append(new_image)
# case DynamoDBRecordEventName.REMOVE:
# remove_docs.append(new_image)
# case _:
# add_docs.append(new_image)
# print(add_docs)
# meili_client.index('users').add_documents(add_docs, serializer=JSONEncoder)
def table_from_arn(arn: str) -> str:
arn_ = arnparse(arn)
return arn_.resource.split('/')[0]