|
| 1 | +# Concurrency control schedules |
| 2 | +# Office hour start |
| 3 | +resource "aws_cloudwatch_event_rule" "bulk_upload_concurrency_office_hours_start" { |
| 4 | + name = "bulk-upload-office-hours-start" |
| 5 | + schedule_expression = "cron(0 9 * * ? *)" |
| 6 | +} |
| 7 | + |
| 8 | +resource "aws_cloudwatch_event_target" "bulk_upload_concurrency_office_hours_start" { |
| 9 | + rule = aws_cloudwatch_event_rule.bulk_upload_concurrency_office_hours_start.name |
| 10 | + target_id = "office-hours-start" |
| 11 | + arn = module.concurrency_controller.arn |
| 12 | + |
| 13 | + input = jsonencode({ |
| 14 | + targetFunction = var.bulk_upload_lambda_name |
| 15 | + reservedConcurrency = var.office_hours_start_concurrency |
| 16 | + }) |
| 17 | +} |
| 18 | + |
| 19 | +# Office hours stop |
| 20 | +resource "aws_cloudwatch_event_rule" "bulk_upload_concurrency_office_hours_stop" { |
| 21 | + name = "bulk-upload-office-hours-stop" |
| 22 | + schedule_expression = "cron(0 17 * * ? *)" |
| 23 | +} |
| 24 | + |
| 25 | +resource "aws_cloudwatch_event_target" "bulk_upload_concurrency_office_hours_stop" { |
| 26 | + rule = aws_cloudwatch_event_rule.bulk_upload_office_hours_stop.name |
| 27 | + target_id = "office-hours-stop" |
| 28 | + arn = module.concurrency_controller.arn |
| 29 | + |
| 30 | + input = jsonencode({ |
| 31 | + targetFunction = var.bulk_upload_lambda_name |
| 32 | + reservedConcurrency = var.office_hours_end_concurrency |
| 33 | + }) |
| 34 | +} |
| 35 | + |
| 36 | +# Concurrency control triggers |
| 37 | +# Concurrency freeze during ECS deploy |
| 38 | +resource "aws_cloudwatch_event_rule" "bulk_upload_concurrency_deploy" { |
| 39 | + name = "bulk-upload-concurrency-deploy" |
| 40 | + event_pattern = jsonencode({ |
| 41 | + source = ["deploy.pipeline"] |
| 42 | + detail-type = ["freeze-concurrency"] |
| 43 | + }) |
| 44 | +} |
| 45 | + |
| 46 | +resource "aws_cloudwatch_event_target" "bulk_upload_concurrency_deploy" { |
| 47 | + rule = aws_cloudwatch_event_rule.bulk_upload_concurrency_deploy.name |
| 48 | + target_id = "freeze-concurrency" |
| 49 | + arn = module.concurrency_controller.arn |
| 50 | + |
| 51 | + input = jsonencode({ |
| 52 | + targetFunction = var.bulk_upload_lambda_name |
| 53 | + reservedConcurrency = 0 |
| 54 | + }) |
| 55 | +} |
| 56 | + |
| 57 | +# Restore concurrency after release |
| 58 | +resource "aws_cloudwatch_event_rule" "bulk_upload_concurrency_release_restore" { |
| 59 | + name = "bulk-upload-concurrency-release-restore" |
| 60 | + event_pattern = jsonencode({ |
| 61 | + source = ["release.pipeline"] |
| 62 | + detail-type = ["restore-bulk-upload-concurrency"] |
| 63 | + }) |
| 64 | +} |
| 65 | + |
| 66 | +resource "aws_cloudwatch_event_target" "bulk_upload_concurrency_release_restore" { |
| 67 | + rule = aws_cloudwatch_event_rule.bulk_upload_concurrency_release_restore.name |
| 68 | + target_id = "restore-bulk-upload-concurrency" |
| 69 | + arn = module.concurrency_controller.arn |
| 70 | + |
| 71 | + input = jsonencode({ |
| 72 | + targetFunction = var.bulk_upload_lambda_name |
| 73 | + reservedConcurrency = local.bulk_upload_lambda_concurrent_limit |
| 74 | + }) |
| 75 | +} |
0 commit comments