49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
from aws_lambda_powertools import Logger
|
|
from aws_lambda_powertools.utilities.data_classes import (
|
|
EventBridgeEvent,
|
|
event_source,
|
|
)
|
|
from aws_lambda_powertools.utilities.typing import LambdaContext
|
|
from layercake.dateutils import now
|
|
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair
|
|
|
|
from boto3clients import dynamodb_client
|
|
from config import ENROLLMENT_TABLE
|
|
|
|
logger = Logger(__name__)
|
|
enrollment_layer = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
|
|
|
|
|
|
@event_source(data_class=EventBridgeEvent)
|
|
@logger.inject_lambda_context
|
|
def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
|
new_image = event.detail['new_image']
|
|
now_ = now()
|
|
|
|
with enrollment_layer.transact_items() as transact:
|
|
transact.update(
|
|
key=KeyPair(new_image['id'], '0'),
|
|
update_expr='SET #status = :expired, update_date = :update_date',
|
|
cond_expr='#status IN (:pending, :in_progress)',
|
|
expr_attr_names={
|
|
'#status': 'status',
|
|
},
|
|
expr_attr_values={
|
|
':expired': 'EXPIRED',
|
|
':pending': 'PENDING',
|
|
':in_progress': 'IN_PROGRESS',
|
|
':update_date': now_,
|
|
},
|
|
)
|
|
transact.put(
|
|
item={
|
|
'id': new_image['id'],
|
|
'sk': 'expired_date',
|
|
'create_date': now_,
|
|
},
|
|
)
|
|
|
|
transact.write_items()
|
|
|
|
return True
|