-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcloudwatch_event.tf
58 lines (50 loc) · 1.19 KB
/
cloudwatch_event.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
# Scale Up
resource "aws_cloudwatch_event_rule" "scale_up" {
name = "${var.cluster_name}-asg-scale-up"
description = "Capture each scale up"
event_pattern = <<PATTERN
{
"source": [
"aws.autoscaling"
],
"detail-type": [
"EC2 Instance Launch Successful"
],
"detail": {
"AutoScalingGroupName": [
"${var.auto_scaling_group_name}"
]
}
}
PATTERN
}
resource "aws_cloudwatch_event_target" "lambdaTriggerUp" {
rule = "${aws_cloudwatch_event_rule.scale_up.name}"
target_id = "lamdaFunction"
arn = "${aws_lambda_function.lambda_shuffler.arn}"
}
# Scale Down
resource "aws_cloudwatch_event_rule" "scale_down" {
name = "${var.cluster_name}-asg-scale-down"
description = "Capture each scale down"
event_pattern = <<PATTERN
{
"source": [
"aws.autoscaling"
],
"detail-type": [
"EC2 Instance Terminate Successful"
],
"detail": {
"AutoScalingGroupName": [
"${var.auto_scaling_group_name}"
]
}
}
PATTERN
}
resource "aws_cloudwatch_event_target" "lambdaTriggerDown" {
rule = "${aws_cloudwatch_event_rule.scale_down.name}"
target_id = "lamdaFunction"
arn = "${aws_lambda_function.lambda_shuffler.arn}"
}