forked from magenx/Magento-2-aws-cluster-terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cronjob.tf
28 lines (23 loc) · 1.55 KB
/
cronjob.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//////////////////////////////////////////////////////[ CRON ]////////////////////////////////////////////////////////////
# # ---------------------------------------------------------------------------------------------------------------------#
# Create EventBridge rule to run Magento cronjob
# # ---------------------------------------------------------------------------------------------------------------------#
resource "aws_cloudwatch_event_rule" "cronjob" {
name = "${local.project}-EventBridge-Rule-Run-Magento-Cronjob"
description = "EventBridge rule to run Magento cronjob every minute"
schedule_expression = "rate(1 minute)"
}
# # ---------------------------------------------------------------------------------------------------------------------#
# Create EventBridge target to execute SSM command
# # ---------------------------------------------------------------------------------------------------------------------#
resource "aws_cloudwatch_event_target" "cronjob" {
rule = aws_cloudwatch_event_rule.cronjob.name
target_id = "${local.project}-EventBridge-Target-Admin-Instance-Cron"
arn = "arn:aws:ssm:${data.aws_region.current.name}::document/AWS-RunShellScript"
role_arn = aws_iam_role.eventbridge_service_role.arn
input = "{\"commands\":[\"su ${var.app["brand"]} -s /bin/bash -c '/home/${var.app["brand"]}/public_html/bin/magento cron:run 2>&1'\"],\"executionTimeout\":[\"180\"]}"
run_command_targets {
key = "tag:Name"
values = [aws_launch_template.this["admin"].tag_specifications[0].tags.Name]
}
}