AWSTemplateFormatVersion: 2010-09-09 Transform: AWS::Serverless-2016-10-31 Parameters: UserTable: Type: String Default: betaeducacao-prod-users_d2o3r5gmm4it7j EnrollmentTable: Type: String Default: betaeducacao-prod-enrollments CourseTable: Type: String Default: saladeaula_courses OrderTable: Type: String Default: betaeducacao-prod-orders Globals: Function: CodeUri: app/ Runtime: python3.13 Tracing: Active Architectures: - x86_64 Layers: - !Sub arn:aws:lambda:sa-east-1:336641857101:layer:layercake:94 Environment: Variables: TZ: America/Sao_Paulo LOG_LEVEL: DEBUG DYNAMODB_PARTITION_KEY: id POWERTOOLS_LOGGER_SAMPLE_RATE: 0.1 POWERTOOLS_LOGGER_LOG_EVENT: true USER_TABLE: !Ref UserTable ENROLLMENT_TABLE: !Ref EnrollmentTable ORDER_TABLE: !Ref OrderTable COURSE_TABLE: !Ref CourseTable Resources: EventLog: Type: AWS::Logs::LogGroup Properties: RetentionInDays: 90 EventSetSubscriptionCoveredFunction: Type: AWS::Serverless::Function Properties: Handler: events.stopgap.set_subscription_covered.lambda_handler LoggingConfig: LogGroup: !Ref EventLog Policies: - DynamoDBCrudPolicy: TableName: !Ref EnrollmentTable - DynamoDBReadPolicy: TableName: !Ref UserTable Events: DynamoDBEvent: Type: EventBridgeRule Properties: Pattern: resources: [!Ref EnrollmentTable] detail-type: [INSERT] detail: new_image: sk: ["0"] # Post-migration: rename `tenant_id` to `org_id` tenant_id: - exists: true EventPatchCourseMetadataFunction: Type: AWS::Serverless::Function Properties: Handler: events.stopgap.patch_course_metadata.lambda_handler LoggingConfig: LogGroup: !Ref EventLog Policies: - DynamoDBCrudPolicy: TableName: !Ref EnrollmentTable Events: DynamoDBEvent: Type: EventBridgeRule Properties: Pattern: resources: [!Ref EnrollmentTable] detail-type: [INSERT] detail: new_image: sk: ["0"] EventPatchKonvivaFunction: Type: AWS::Serverless::Function Properties: Handler: events.stopgap.patch_konviva.lambda_handler LoggingConfig: LogGroup: !Ref EventLog Policies: - DynamoDBWritePolicy: TableName: !Ref EnrollmentTable - DynamoDBReadPolicy: TableName: !Ref UserTable - DynamoDBReadPolicy: TableName: !Ref CourseTable Events: DynamoDBEvent: Type: EventBridgeRule Properties: Pattern: resources: [!Ref EnrollmentTable] detail-type: [INSERT] detail: new_image: sk: ["0"] EventEnrollFunction: Type: AWS::Serverless::Function Properties: Handler: events.enroll.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: [betaeducacao-prod-orders] detail-type: [INSERT] detail: new_image: # Post-migration: uncomment the following lines # sk: [SLOT] # mode: [STANDALONE] sk: [generated_items] scope: [SINGLE_USER] status: [PENDING] EventReenrollIfFailedFunction: Type: AWS::Serverless::Function Properties: Handler: events.reenroll_if_failed.lambda_handler LoggingConfig: LogGroup: !Ref EventLog Policies: - DynamoDBCrudPolicy: TableName: !Ref EnrollmentTable Events: DynamoDBEvent: Type: EventBridgeRule Properties: Pattern: resources: [!Ref EnrollmentTable] detail-type: [MODIFY] detail: changes: [status] new_image: sk: ["0"] status: [FAILED] score: - numeric: ["<", 70] old_image: status: [IN_PROGRESS] EventAllocateSlotsFunction: Type: AWS::Serverless::Function Properties: Handler: events.allocate_slots.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: # Post-migration: uncomment the following lines # sk: [SLOT] # mode: [BATCH] sk: [generated_items] scope: [MULTI_USER] status: [PENDING] SesPolicy: Type: AWS::IAM::ManagedPolicy Properties: PolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Action: - ses:SendRawEmail Resource: - !Sub arn:aws:ses:${AWS::Region}:${AWS::AccountId}:identity/eduseg.com.br - !Sub arn:aws:ses:${AWS::Region}:${AWS::AccountId}:configuration-set/tracking # If the user does not access the course within 3 days after enrollment creation EventReminderNoAccessAfter3DaysFunction: Type: AWS::Serverless::Function Properties: Handler: events.emails.reminder_no_access_after_3_days.lambda_handler LoggingConfig: LogGroup: !Ref EventLog Policies: - !Ref SesPolicy - DynamoDBCrudPolicy: TableName: !Ref EnrollmentTable Events: DynamoDBEvent: Type: EventBridgeRule Properties: Pattern: resources: [!Ref EnrollmentTable] detail-type: [EXPIRE] detail: keys: sk: - SCHEDULE#REMINDER_NO_ACCESS_AFTER_3_DAYS # Post-migration: remove the following lines - schedules#does_not_access - schedules#reminder_no_access_3_days - SCHEDULES#REMINDER_NO_ACCESS_AFTER_3_DAYS # 7 days after the user's last activity in the course EventReminderNoActivityAfter7DaysFunction: Type: AWS::Serverless::Function Properties: Handler: events.emails.reminder_no_activity_after_7_days.lambda_handler LoggingConfig: LogGroup: !Ref EventLog Policies: - !Ref SesPolicy - DynamoDBCrudPolicy: TableName: !Ref EnrollmentTable Events: DynamoDBEvent: Type: EventBridgeRule Properties: Pattern: resources: [!Ref EnrollmentTable] detail-type: [EXPIRE] detail: keys: sk: - SCHEDULE#REMINDER_NO_ACTIVITY_AFTER_7_DAYS # Post-migration: remove the following line - schedules#no_activity # 30 days before the course access period ends. EventReminderAccessPeriodBefore30DaysFunction: Type: AWS::Serverless::Function Properties: Handler: events.emails.reminder_access_period_before_30_days.lambda_handler LoggingConfig: LogGroup: !Ref EventLog Policies: - !Ref SesPolicy - DynamoDBCrudPolicy: TableName: !Ref EnrollmentTable Events: DynamoDBEvent: Type: EventBridgeRule Properties: Pattern: resources: [!Ref EnrollmentTable] detail-type: [EXPIRE] detail: keys: sk: - SCHEDULE#REMINDER_CERT_EXPIRATION_BEFORE_30_DAYS # Post-migration: remove the following line - schedules#access_period_ends # If a certificate exists, remind the user 30 days before the certificate expires EventReminderCertExpirationBefore30DaysFunction: Type: AWS::Serverless::Function Properties: Handler: events.emails.reminder_cert_expiration_before_30_days.lambda_handler LoggingConfig: LogGroup: !Ref EventLog Policies: - !Ref SesPolicy - DynamoDBCrudPolicy: TableName: !Ref EnrollmentTable Events: DynamoDBEvent: Type: EventBridgeRule Properties: Pattern: resources: [!Ref EnrollmentTable] detail-type: [EXPIRE] detail: keys: sk: - SCHEDULE#REMINDER_CERT_EXPIRATION_BEFORE_30_DAYS # Post-migration: remove the following line - schedules#expiration EventScheduleRemindersFunction: Type: AWS::Serverless::Function Properties: Handler: events.schedule_reminders.lambda_handler LoggingConfig: LogGroup: !Ref EventLog Policies: - DynamoDBCrudPolicy: TableName: !Ref EnrollmentTable Events: DynamoDBEvent: Type: EventBridgeRule Properties: Pattern: resources: [!Ref EnrollmentTable] detail-type: [INSERT] detail: new_image: sk: ["0"] status: [PENDING] EventIssueCertFunction: Type: AWS::Serverless::Function Properties: Handler: events.issue_cert.lambda_handler LoggingConfig: LogGroup: !Ref EventLog Events: DynamoDBEvent: Type: EventBridgeRule Properties: Pattern: resources: [!Ref EnrollmentTable] detail: keys: sk: ["0"] new_image: status: [COMPLETED] old_image: status: [IN_PROGRESS]