This commit is contained in:
2025-05-27 12:15:22 -03:00
parent 270e408c1d
commit 42e62ec183
30 changed files with 287 additions and 178 deletions

View File

@@ -13,7 +13,7 @@ from layercake.dynamodb import (
)
from boto3clients import dynamodb_client
from conf import ORDER_TABLE, USER_TABLE
from config import ORDER_TABLE, USER_TABLE
logger = Logger(__name__)
user_layer = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)
@@ -39,7 +39,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
flatten_top=False,
)
# Sometimes, a DynamoDB insertion may take longer to complete,
# Sometimes the function executes before the user insertion completes,
# so an exception is raised to trigger a retry.
if len(ids) < 2:
raise ValueError('IDs not found.')

View File

@@ -9,7 +9,7 @@ from layercake.dynamodb import (
)
from boto3clients import dynamodb_client
from conf import ORDER_TABLE, USER_TABLE
from config import ORDER_TABLE, USER_TABLE
logger = Logger(__name__)
user_layer = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)

View File

@@ -8,10 +8,11 @@ from layercake.dateutils import now
from layercake.dynamodb import (
DynamoDBPersistenceLayer,
KeyPair,
TransactItems,
)
from boto3clients import dynamodb_client
from conf import ORDER_TABLE
from config import ORDER_TABLE
logger = Logger(__name__)
order_layer = DynamoDBPersistenceLayer(ORDER_TABLE, dynamodb_client)
@@ -21,7 +22,9 @@ order_layer = DynamoDBPersistenceLayer(ORDER_TABLE, dynamodb_client)
@logger.inject_lambda_context
def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
new_image = event.detail['new_image']
order_layer.update_item(
now_ = now()
transact = TransactItems(order_layer.table_name)
transact.update(
key=KeyPair(new_image['id'], '0'),
update_expr='SET #status = :status, update_date = :update_date',
expr_attr_names={
@@ -29,8 +32,15 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
},
expr_attr_values={
':status': 'PAID',
':update_date': now(),
':update_date': now_,
},
)
transact.put(
item={
'id': new_image['id'],
'sk': 'paid_date',
'create_date': now_,
}
)
order_layer.transact_write_items(transact)
return True