add test_mode
This commit is contained in:
39
orders-events/app/events/run_self_destruction.py
Normal file
39
orders-events/app/events/run_self_destruction.py
Normal file
@@ -0,0 +1,39 @@
|
||||
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.dynamodb import (
|
||||
DynamoDBPersistenceLayer,
|
||||
PartitionKey,
|
||||
)
|
||||
|
||||
from boto3clients import dynamodb_client
|
||||
from config import ORDER_TABLE
|
||||
|
||||
logger = Logger(__name__)
|
||||
dyn = DynamoDBPersistenceLayer(ORDER_TABLE, dynamodb_client)
|
||||
|
||||
|
||||
@event_source(data_class=EventBridgeEvent)
|
||||
@logger.inject_lambda_context
|
||||
def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
keys = event.detail['keys']
|
||||
order_id = keys['id']
|
||||
|
||||
r = dyn.collection.query(PartitionKey(order_id), limit=150)
|
||||
logger.info('Records found', total_items=len(r['items']), records=r['items'])
|
||||
|
||||
with dyn.batch_writer() as batch:
|
||||
for pair in r['items']:
|
||||
batch.delete_item(
|
||||
Key={
|
||||
'id': {'S': pair['id']},
|
||||
'sk': {'S': pair['sk']},
|
||||
}
|
||||
)
|
||||
|
||||
logger.info('Deleted all records')
|
||||
|
||||
return True
|
||||
@@ -96,6 +96,8 @@ Resources:
|
||||
detail:
|
||||
new_image:
|
||||
sk: ['0']
|
||||
payment_method:
|
||||
- anything-but: [MANUAL]
|
||||
|
||||
EventPaymentsChargeCreditCardFunction:
|
||||
Type: AWS::Serverless::Function
|
||||
@@ -245,6 +247,26 @@ Resources:
|
||||
old_image:
|
||||
status: [PENDING]
|
||||
|
||||
EventRunSelfDestructionFunction:
|
||||
Type: AWS::Serverless::Function
|
||||
Properties:
|
||||
Handler: events.run_self_destruction.lambda_handler
|
||||
LoggingConfig:
|
||||
LogGroup: !Ref EventLog
|
||||
Policies:
|
||||
- DynamoDBCrudPolicy:
|
||||
TableName: !Ref OrderTable
|
||||
Events:
|
||||
Event:
|
||||
Type: EventBridgeRule
|
||||
Properties:
|
||||
Pattern:
|
||||
resources: [!Ref OrderTable]
|
||||
detail-type: [EXPIRE]
|
||||
detail:
|
||||
keys:
|
||||
sk: ['SCHEDULE#SELF_DESTRUCTION']
|
||||
|
||||
# DEPRECATED
|
||||
EventAppendOrgIdFunction:
|
||||
Type: AWS::Serverless::Function
|
||||
|
||||
Reference in New Issue
Block a user