update fix to unit price
This commit is contained in:
@@ -5,7 +5,7 @@ from aws_lambda_powertools.utilities.data_classes import (
|
||||
)
|
||||
from aws_lambda_powertools.utilities.typing import LambdaContext
|
||||
from layercake.dateutils import now
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair
|
||||
|
||||
from boto3clients import dynamodb_client
|
||||
from config import API_URL, COURSE_TABLE
|
||||
@@ -21,15 +21,16 @@ def lambda_handler(event: DynamoDBStreamEvent, context: LambdaContext) -> bool:
|
||||
data = r.json()
|
||||
now_ = now()
|
||||
|
||||
with course_layer.batch_writer() as batch:
|
||||
with course_layer.transact_writer() as transact:
|
||||
for course in data:
|
||||
batch.put_item(
|
||||
{
|
||||
'id': {'S': course['id']},
|
||||
'sk': {'S': 'metadata#unit_price'},
|
||||
'unit_price': {'N': str(course['metadata']['unit_price'])},
|
||||
'create_date': {'S': now_.isoformat()},
|
||||
}
|
||||
transact.update(
|
||||
key=KeyPair(course['id'], '0'),
|
||||
update_expr='SET metadata__unit_price = :unit_price, \
|
||||
updated_at = :updated_at',
|
||||
expr_attr_values={
|
||||
':unit_price': course['metadata']['unit_price'],
|
||||
':updated_at': now_,
|
||||
},
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user