wip subscription org
This commit is contained in:
@@ -71,7 +71,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
|
||||
class CourseNotFoundError(Exception):
|
||||
def __init__(self, *args):
|
||||
super().__init__('Course not found')
|
||||
super().__init__('Course not found in SQLite')
|
||||
|
||||
|
||||
# Post-migration: remove the following function
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
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,
|
||||
USER_TABLE,
|
||||
)
|
||||
|
||||
logger = Logger(__name__)
|
||||
user_layer = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)
|
||||
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']
|
||||
data = user_layer.get_item(
|
||||
# Post-migration: uncomment the following line
|
||||
# KeyPair(new_image['org_id'], 'METADATA#BILLING_TERMS'),
|
||||
KeyPair(new_image['tenant_id'], 'metadata#billing_policy'),
|
||||
)
|
||||
|
||||
if not data:
|
||||
return False
|
||||
|
||||
try:
|
||||
enrollment_layer.put_item(
|
||||
item={
|
||||
'id': new_image['id'],
|
||||
'sk': 'METADATA#BILLING_TERMS',
|
||||
'org_id': new_image['tenant_id'],
|
||||
'billing_day': data['billing_day'],
|
||||
'created_at': now(),
|
||||
},
|
||||
cond_expr='attribute_not_exists(sk)',
|
||||
)
|
||||
except Exception:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
Reference in New Issue
Block a user