-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventbridge.tf
46 lines (38 loc) · 1.4 KB
/
eventbridge.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
#--eventbriged/main--
resource "aws_cloudwatch_event_rule" "start_event_rule" {
name = "start-bim-large-ec2"
schedule_expression = "cron(0 12 * * ? *)"
tags = {
Project = "large_ec2"
}
}
resource "aws_cloudwatch_event_target" "start_event_lambda_target" {
rule = aws_cloudwatch_event_rule.start_event_rule.name
arn = aws_lambda_function.ec2_start_large_lambda.arn
}
resource "aws_lambda_permission" "allow_start_event_rule_schedule" {
statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.ec2_start_large_lambda.function_name
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.start_event_rule.arn
}
#---stop---
resource "aws_cloudwatch_event_rule" "stop_event_rule" {
name = "stop-bim-large-ec2"
schedule_expression = "cron(0 18 * * ? *)"
tags = {
Project = "large_ec2"
}
}
resource "aws_cloudwatch_event_target" "stop_event_lambda_target" {
rule = aws_cloudwatch_event_rule.stop_event_rule.name
arn = aws_lambda_function.ec2_stop_large_lambda.arn
}
resource "aws_lambda_permission" "allow_stop_event_rule_schedule" {
statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.ec2_stop_large_lambda.function_name
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.stop_event_rule.arn
}