-
Notifications
You must be signed in to change notification settings - Fork 1
/
primary-region-alarms.yml
112 lines (107 loc) · 3.05 KB
/
primary-region-alarms.yml
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Parameters:
DeploymentBucket:
Type: String
PrimaryHealthCheckId:
Type: String
CloudFrontDistributionDomainName:
Type: String
HostedZoneName:
Type: String
PrimaryUrl:
Type: String
StandbyUrl:
Type: String
MyInfraStackName:
Type: String
MyInfraStackRegion:
Type: String
OtherInfraStackName:
Type: String
OtherInfraStackRegion:
Type: String
AdminContactEmail:
Type: String
Outputs:
PrimaryHealthCheckSNSArn:
Description: SNS Arn
Value: !Ref PrimaryHealthCheckSNS
Resources:
PrimaryHealthCheckSNS:
Type: AWS::SNS::Topic
Properties:
Subscription:
- Endpoint: !Ref AdminContactEmail
Protocol: email
# NOTE: The alarm MUST be in us-east-1
PrimaryHealthCheckFailedAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
ActionsEnabled: 'true'
AlarmActions: [ !Ref PrimaryHealthCheckSNS ]
AlarmDescription: !Ref CloudFrontDistributionDomainName
ComparisonOperator: LessThanThreshold
EvaluationPeriods: '1'
MetricName: HealthCheckStatus
Namespace: AWS/Route53
Period: '60'
Statistic: Minimum
Threshold: '1.0'
Dimensions:
- Name: HealthCheckId
Value: !Ref PrimaryHealthCheckId
PrimaryHealthCheckFunction:
Type: "AWS::Serverless::Function"
Properties:
Handler: main.lambda_handler
Runtime: python2.7
CodeUri:
Bucket: !Ref DeploymentBucket
Key: deployment.zip
Description: Updates CF distro and Route53
MemorySize: 128
Timeout: 60
Policies:
- Statement:
Effect: Allow
Action:
- 'route53:ListHostedZonesByName'
- 'route53:ListResourceRecordSets'
Resource: '*'
- Statement:
Effect: Allow
Action:
- 'cloudfront:GetDistributionConfig'
- 'cloudfront:UpdateDistribution'
Resource: '*'
- Statement:
Effect: Allow
Action:
- 'cloudformation:DescribeStacks'
- 'cloudformation:GetTemplate'
- 'cloudformation:UpdateStack'
Resource: '*'
# Needed for the lambda to update cloudformation
- Statement:
Effect: Allow
Action:
- 'cloudfront:GetDistribution'
- 'route53:ListHostedZones'
- 'route53:ChangeResourceRecordSets'
- 'route53:GetChange'
Resource: '*'
Environment:
Variables:
HostedZoneName: !Ref HostedZoneName
PrimaryUrl: !Ref PrimaryUrl
StandbyUrl: !Ref StandbyUrl
MyInfraStackName: !Ref MyInfraStackName
MyInfraStackRegion: !Ref MyInfraStackRegion
OtherInfraStackName: !Ref OtherInfraStackName
OtherInfraStackRegion: !Ref OtherInfraStackRegion
Events:
SNS:
Type: SNS
Properties:
Topic: !Ref PrimaryHealthCheckSNS