update
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
import os
|
||||
|
||||
USER_TABLE: str = os.getenv('USER_TABLE') # type: ignore
|
||||
ORDER_TABLE: str = os.getenv('ORDER_TABLE') # type: ignore
|
||||
ENROLLMENT_TABLE: str = os.getenv('ENROLLMENT_TABLE') # type: ignore
|
||||
@@ -4,10 +4,43 @@ from aws_lambda_powertools.utilities.data_classes import (
|
||||
event_source,
|
||||
)
|
||||
from aws_lambda_powertools.utilities.typing import LambdaContext
|
||||
from layercake.dateutils import now
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair, TransactItems
|
||||
|
||||
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) -> None: ...
|
||||
def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
new_image = event.detail['new_image']
|
||||
now_ = now()
|
||||
transact = TransactItems(enrollment_layer.table_name)
|
||||
transact.update(
|
||||
key=KeyPair(new_image['id'], '0'),
|
||||
update_expr='SET #status = :archived, update_date = :update_date',
|
||||
cond_expr='#status = :completed',
|
||||
expr_attr_names={
|
||||
'#status': 'status',
|
||||
},
|
||||
expr_attr_values={
|
||||
':archived': 'ARCHIVED',
|
||||
':completed': 'COMPLETED',
|
||||
':update_date': now_,
|
||||
},
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
'id': new_image['id'],
|
||||
'sk': 'archived_date',
|
||||
'create_date': now_,
|
||||
},
|
||||
)
|
||||
|
||||
enrollment_layer.transact_write_items(transact)
|
||||
|
||||
return True
|
||||
|
||||
@@ -13,7 +13,7 @@ from layercake.dynamodb import (
|
||||
)
|
||||
|
||||
from boto3clients import dynamodb_client
|
||||
from conf import ENROLLMENT_TABLE, ORDER_TABLE, USER_TABLE
|
||||
from config import ENROLLMENT_TABLE, ORDER_TABLE, USER_TABLE
|
||||
|
||||
logger = Logger(__name__)
|
||||
user_layer = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)
|
||||
|
||||
@@ -30,6 +30,7 @@ Globals:
|
||||
POWERTOOLS_LOGGER_LOG_EVENT: true
|
||||
USER_TABLE: !Ref UserTable
|
||||
ENROLLMENT_TABLE: !Ref EnrollmentTable
|
||||
ORDER_TABLE: !Ref OrderTable
|
||||
|
||||
Resources:
|
||||
EventLog:
|
||||
@@ -40,7 +41,7 @@ Resources:
|
||||
EventDelVacanciesFunction:
|
||||
Type: AWS::Serverless::Function
|
||||
Properties:
|
||||
Handler: events.del_vacancies.lambda_handler
|
||||
Handler: events.stopgap.del_vacancies.lambda_handler
|
||||
LoggingConfig:
|
||||
LogGroup: !Ref EventLog
|
||||
Policies:
|
||||
@@ -60,3 +61,43 @@ Resources:
|
||||
new_image:
|
||||
sk: [generated_items]
|
||||
status: [SUCCESS]
|
||||
|
||||
EventSetStatusAsArchivedFunction:
|
||||
Type: AWS::Serverless::Function
|
||||
Properties:
|
||||
Handler: events.set_status_as_archived.lambda_handler
|
||||
LoggingConfig:
|
||||
LogGroup: !Ref EventLog
|
||||
Policies:
|
||||
- DynamoDBWritePolicy:
|
||||
TableName: !Ref EnrollmentTable
|
||||
Events:
|
||||
DynamoDBEvent:
|
||||
Type: EventBridgeRule
|
||||
Properties:
|
||||
Pattern:
|
||||
resources: [!Ref EnrollmentTable]
|
||||
detail-type: [EXPIRE]
|
||||
detail:
|
||||
keys:
|
||||
sk: [schedules#course_archived]
|
||||
|
||||
EventSetStatusAsExpiredFunction:
|
||||
Type: AWS::Serverless::Function
|
||||
Properties:
|
||||
Handler: events.set_status_as_expired.lambda_handler
|
||||
LoggingConfig:
|
||||
LogGroup: !Ref EventLog
|
||||
Policies:
|
||||
- DynamoDBWritePolicy:
|
||||
TableName: !Ref EnrollmentTable
|
||||
Events:
|
||||
DynamoDBEvent:
|
||||
Type: EventBridgeRule
|
||||
Properties:
|
||||
Pattern:
|
||||
resources: [!Ref EnrollmentTable]
|
||||
detail-type: [EXPIRE]
|
||||
detail:
|
||||
keys:
|
||||
sk: [schedules#course_expired]
|
||||
|
||||
Reference in New Issue
Block a user