This commit is contained in:
2026-01-21 21:31:32 -03:00
parent 26c3df876f
commit 37a9b20188
38 changed files with 1009 additions and 532 deletions

View File

@@ -9,6 +9,7 @@ from aws_lambda_powertools.event_handler.api_gateway import (
)
from aws_lambda_powertools.logging import correlation_paths
from aws_lambda_powertools.utilities.typing import LambdaContext
from layercake.dateutils import now
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair
from boto3clients import dynamodb_client, s3_client
@@ -53,8 +54,14 @@ def postback():
dyn.update_item(
key=KeyPair(enrollment_id, '0'),
cond_expr='attribute_exists(sk)',
update_expr='SET cert.s3_uri = :s3_uri',
expr_attr_values={':s3_uri': s3_uri},
update_expr='SET cert.s3_uri = :s3_uri, \
cert.signed = :true, \
updated_at = :now',
expr_attr_values={
':s3_uri': s3_uri,
':true': True,
':now': now(),
},
)
return Response(status_code=HTTPStatus.NO_CONTENT)

View File

@@ -7,7 +7,9 @@ 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
from layercake.funcs import omit
from layercake.strutils import first_word
from boto3clients import dynamodb_client, s3_client
@@ -52,7 +54,15 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
},
],
)
logger.debug(r)
dyn.put_item(
item={
'id': new_image['id'],
'sk': 'METADATA#DOCUSEAL',
'snapshot': omit(('fields',), r),
'created_at': now(),
}
)
return True

View File

@@ -21,11 +21,12 @@ dyn = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
@logger.inject_lambda_context
def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
old_image = event.detail['old_image']
sk = old_image['sk']
_, lock_hash = sk.split('#')
now_ = now()
# Key pattern `SCHEDULED#ORG#{org_id}`
*_, org_id = old_image['id'].split('#')
# Key pattern `{YYYY-MM-DD HH:MM:SS.mmmmmm}#{lock_hash}`
sk = old_image['sk']
_, lock_hash = sk.split('#')
offset_days = old_image.get('dedup_window_offset_days')
billing_day = old_image.get('subscription_billing_day')
created_by = old_image.get('created_by')

View File

@@ -1,32 +0,0 @@
# from uuid import uuid4
from aws_durable_execution_sdk_python import DurableContext, durable_execution
from aws_lambda_powertools import Logger
from aws_lambda_powertools.utilities.data_classes import (
EventBridgeEvent,
event_source,
)
# from layercake.dateutils import now
logger = Logger(__name__)
@event_source(data_class=EventBridgeEvent)
@durable_execution
def lambda_handler(event: EventBridgeEvent, context: DurableContext) -> bool:
# new_image = event.detail['new_image']
# now_ = now()
# org_id = ''
# order_id = new_image['id']
# docx = {
# 'id': f'SEAT#ORG#{org_id}',
# 'sk': f'ORDER#{order_id}#ENROLLMENT#{uuid4()}',
# 'course': {},
# 'created_at': now_,
logger.info(event)
# }
return True

View File

@@ -19,7 +19,7 @@ dev = [
[tool.pytest.ini_options]
pythonpath = ["app/"]
addopts = "--cov --cov-report html -v"
addopts = "--cov=app --cov-report html"
[tool.ruff]
target-version = "py311"

View File

@@ -1,4 +1,4 @@
AWSTemplateFormatVersion: 2010-09-09
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Parameters:
@@ -21,11 +21,11 @@ Parameters:
Globals:
Function:
CodeUri: app/
Runtime: python3.13
Runtime: python3.14
Architectures:
- x86_64
Layers:
- !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:layer:layercake:104
- !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:layer:layercake:106
Environment:
Variables:
TZ: America/Sao_Paulo
@@ -179,8 +179,10 @@ Resources:
detail:
new_image:
# Post-migration: uncomment the following lines
# sk: [SLOT]
# mode: [STANDALONE]
# sk: [FULFILLMENT]
# status: [IN_PROGRESS]
# user_id:
# - exists: true
sk: [generated_items]
scope: [SINGLE_USER]
status: [PENDING]
@@ -194,7 +196,7 @@ Resources:
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref EnrollmentTable
- DynamoDBReadPolicy:
- DynamoDBCrudPolicy:
TableName: !Ref UserTable
Events:
DynamoDBEvent:
@@ -217,6 +219,8 @@ Resources:
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref EnrollmentTable
- DynamoDBCrudPolicy:
TableName: !Ref UserTable
Events:
DynamoDBEvent:
Type: EventBridgeRule
@@ -234,6 +238,7 @@ Resources:
old_image:
status: [IN_PROGRESS]
# DEPRECATED
EventAllocateSlotsFunction:
Type: AWS::Serverless::Function
Properties:
@@ -256,38 +261,10 @@ Resources:
detail-type: [INSERT]
detail:
new_image:
# Post-migration: uncomment the following lines
# sk: [SLOT]
# mode: [BATCH]
sk: [generated_items]
scope: [MULTI_USER]
status: [PENDING]
EventAllocateSeatsFunction:
Type: AWS::Serverless::Function
Properties:
Handler: events.allocate_seats.lambda_handler
LoggingConfig:
LogGroup: !Ref EventLog
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref OrderTable
- DynamoDBCrudPolicy:
TableName: !Ref EnrollmentTable
- DynamoDBReadPolicy:
TableName: !Ref CourseTable
Events:
DynamoDBEvent:
Type: EventBridgeRule
Properties:
Pattern:
resources: [!Ref OrderTable]
detail-type: [INSERT]
detail:
new_image:
sk: [SEATS_ALLOCATION]
status: [PENDING]
SesPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
@@ -395,8 +372,7 @@ Resources:
Type: AWS::Serverless::Function
Properties:
Handler: events.issue_cert.lambda_handler
Tracing: Active
Timeout: 10
Timeout: 12
LoggingConfig:
LogGroup: !Ref EventLog
Policies:
@@ -417,6 +393,9 @@ Resources:
sk: ['0']
new_image:
status: [COMPLETED]
cert:
issued_at:
- exists: false
old_image:
status: [IN_PROGRESS]
@@ -424,11 +403,12 @@ Resources:
Type: AWS::Serverless::Function
Properties:
Handler: events.ask_to_sign.lambda_handler
Tracing: Active
Timeout: 12
Policies:
- S3ReadPolicy:
BucketName: !Ref BucketName
- DynamoDBCrudPolicy:
TableName: !Ref EnrollmentTable
LoggingConfig:
LogGroup: !Ref EventLog
Events:

File diff suppressed because it is too large Load Diff