forked from widdix/aws-cf-templates
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvpc-nat-gateway.yaml
180 lines (180 loc) · 5.48 KB
/
vpc-nat-gateway.yaml
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
---
# Copyright 2018 widdix GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
AWSTemplateFormatVersion: '2010-09-09'
Description: 'VPC: NAT Gateway, a cloudonaut.io template'
Metadata:
'AWS::CloudFormation::Interface':
ParameterGroups:
- Label:
default: 'Parent Stacks'
Parameters:
- ParentVPCStack
- ParentAlertStack
- Label:
default: 'NatGateway Parameters'
Parameters:
- SubnetZone
Parameters:
ParentVPCStack:
Description: 'Stack name of parent VPC stack based on vpc/vpc-*azs.yaml template.'
Type: String
ParentAlertStack:
Description: 'Optional but recommended stack name of parent alert stack based on operations/alert.yaml template.'
Type: String
Default: ''
SubnetZone:
Description: 'Subnet zone.'
Type: String
Default: A
AllowedValues:
- A
- B
- C
- D
Conditions:
HasAlertTopic: !Not [!Equals [!Ref ParentAlertStack, '']]
Resources:
EIP:
Type: 'AWS::EC2::EIP'
Properties:
Domain: vpc
NatGateway:
Type: 'AWS::EC2::NatGateway'
Properties:
AllocationId: !GetAtt 'EIP.AllocationId'
SubnetId: {'Fn::ImportValue': !Sub '${ParentVPCStack}-Subnet${SubnetZone}Public'}
Route:
Type: 'AWS::EC2::Route'
Properties:
RouteTableId: {'Fn::ImportValue': !Sub '${ParentVPCStack}-RouteTable${SubnetZone}Private'}
DestinationCidrBlock: '0.0.0.0/0'
NatGatewayId: !Ref NatGateway
AlarmNatGatewayErrorPortAllocation:
Condition: HasAlertTopic
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmDescription: !Sub 'NAT gateway ${SubnetZone} could not allocate a source port'
Namespace: 'AWS/NATGateway'
MetricName: ErrorPortAllocation
Statistic: Sum
Period: 60
EvaluationPeriods: 1
ComparisonOperator: GreaterThanThreshold
Threshold: 0
AlarmActions:
- {'Fn::ImportValue': !Sub '${ParentAlertStack}-TopicARN'}
Dimensions:
- Name: NatGatewayId
Value: !Ref NatGateway
AlarmNatGatewayPacketsDropCount:
Condition: HasAlertTopic
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmDescription: !Sub 'NAT gateway ${SubnetZone} dropped packets'
Namespace: 'AWS/NATGateway'
MetricName: PacketsDropCount
Statistic: Sum
Period: 60
EvaluationPeriods: 1
ComparisonOperator: GreaterThanThreshold
Threshold: 0
AlarmActions:
- {'Fn::ImportValue': !Sub '${ParentAlertStack}-TopicARN'}
Dimensions:
- Name: NatGatewayId
Value: !Ref NatGateway
AlarmNatGatewayBandwidth:
Condition: HasAlertTopic
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmActions:
- {'Fn::ImportValue': !Sub '${ParentAlertStack}-TopicARN'}
AlarmDescription: !Sub 'NAT gateway ${SubnetZone} bandwidth utilization is over 80%'
ComparisonOperator: GreaterThanThreshold
EvaluationPeriods: 1
Metrics:
- Id: 'in1'
Label: 'InFromDestination'
MetricStat:
Metric:
Namespace: 'AWS/NATGateway'
MetricName: BytesInFromDestination # bytes per minute
Dimensions:
- Name: NatGatewayId
Value: !Ref NatGateway
Period: 60
Stat: Sum
Unit: Bytes
ReturnData: false
- Id: 'in2'
Label: 'InFromSource'
MetricStat:
Metric:
Namespace: 'AWS/NATGateway'
MetricName: BytesInFromSource # bytes per minute
Dimensions:
- Name: NatGatewayId
Value: !Ref NatGateway
Period: 60
Stat: Sum
Unit: Bytes
ReturnData: false
- Id: 'out1'
Label: 'OutToDestination'
MetricStat:
Metric:
Namespace: 'AWS/NATGateway'
MetricName: BytesOutToDestination # bytes per minute
Dimensions:
- Name: NatGatewayId
Value: !Ref NatGateway
Period: 60
Stat: Sum
Unit: Bytes
ReturnData: false
- Id: 'out2'
Label: 'OutToSource'
MetricStat:
Metric:
Namespace: 'AWS/NATGateway'
MetricName: BytesOutToSource # bytes per minute
Dimensions:
- Name: NatGatewayId
Value: !Ref NatGateway
Period: 60
Stat: Sum
Unit: Bytes
ReturnData: false
- Expression: '(in1+in2+out1+out2)/2/60*8/1000/1000/1000' # to Gbit/s
Id: 'bandwidth'
Label: 'Bandwidth'
ReturnData: true
Threshold: 36 # hard limit is 45 Gbit/s
TreatMissingData: notBreaching
Outputs:
TemplateID:
Description: 'cloudonaut.io template id.'
Value: 'vpc/vpc-nat-gateway'
TemplateVersion:
Description: 'cloudonaut.io template version.'
Value: '__VERSION__'
StackName:
Description: 'Stack name.'
Value: !Sub '${AWS::StackName}'
IPAddress:
Description: 'The public IP address of the NAT gateway.'
Value: !Ref EIP
Export:
Name: !Sub '${AWS::StackName}-IPAddress'