-
Notifications
You must be signed in to change notification settings - Fork 0
/
event-bridge.tf
61 lines (54 loc) · 1.76 KB
/
event-bridge.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
resource "aws_cloudwatch_event_rule" "lambda_ec2start_rule" {
name = "lambda_ec2start_rule"
description = "EventBridge rule to trigger Start EC2 Lambda"
schedule_expression = "cron(0 2 * * ? *)"
}
resource "aws_cloudwatch_event_target" "lambda_target" {
rule = aws_cloudwatch_event_rule.lambda_ec2start_rule.name
target_id = "lambda-target"
arn = aws_lambda_function.start_app_lambda.arn
input_transformer {
input_paths = {
"payload" = "$"
}
input_template = <<EOF
{
"instance-name": "guacamole-app"
}
EOF
}
}
resource "aws_lambda_permission" "event_start_permission" {
statement_id = "AllowEventBridgeInvoke"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.start_app_lambda.function_name
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.lambda_ec2start_rule.arn
}
resource "aws_cloudwatch_event_rule" "lambda_ec2stop_rule" {
name = "lambda_ec2stop_rule"
description = "EventBridge rule to trigger Stop EC2 Lambda"
schedule_expression = "cron(0 15 * * ? *)"
}
resource "aws_cloudwatch_event_target" "lambda_stop_target" {
rule = aws_cloudwatch_event_rule.lambda_ec2stop_rule.name
target_id = "lambda-target"
arn = aws_lambda_function.stop_app_lambda.arn
input_transformer {
input_paths = {
"payload" = "$"
}
input_template = <<EOF
{
"instance-name": "guacamole-app"
}
EOF
}
}
resource "aws_lambda_permission" "event_stop_permission" {
statement_id = "AllowStopEventInvoke"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.stop_app_lambda.function_name
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.lambda_ec2stop_rule.arn
}