11AWSTemplateFormatVersion : ' 2010-09-09'
22Description : Reporting for mobile notifications
33Mappings :
4+ # Static values could be inlined. GuCDK will do this.
45 Constants :
56 App :
67 Value : report
78 Stack :
89 Value : mobile-notifications
910
11+ # These values do not vary by stage, so could be inlined.
1012 StageVariables :
1113 CODE :
1214 NotificationAlarmPeriod : 1200
@@ -36,9 +38,12 @@ Parameters:
3638 - CODE
3739 - PROD
3840 Description : Environment name
41+
42+ # TODO remove as not working as it implies
3943 VPCSecurityGroup :
4044 Type : AWS::EC2::SecurityGroup::Id
4145 Description : The default security group of the VPC
46+
4247 VpcId :
4348 Type : AWS::EC2::VPC::Id
4449 Description : The VPC
@@ -48,24 +53,36 @@ Parameters:
4853 PrivateSubnets :
4954 Type : List<AWS::EC2::Subnet::Id>
5055 Description : The private subnets of the VPC for the autoscaling group
56+
57+ # Could be inlined. GuCDK will do this.
5158 ASGMinSize :
5259 Type : Number
5360 Description : Minimum size of the autoscaling group
61+ # Could be inlined. GuCDK will do this.
5462 ASGMaxSize :
5563 Type : Number
5664 Description : Maximum size of the autoscaling group
65+
66+ # TODO read from SSM Parameters. GuCDK will do this.
5767 DistBucket :
5868 Type : String
5969 Description : The name of the s3 bucket containing the server artifact
70+
71+ # TODO provision this certificate within this stack
6072 AppCertArn :
6173 Type : String
6274 Description : ACM Certificate for app use
75+
76+ # TODO Stage aware value could be moved to StageVariables. GuCDK will simplify this.
6377 HostedZone :
6478 Type : String
6579 Description : The HostedZone, should contain the trailing dot zone.example.com.
80+
81+ # TODO Stage aware value could be moved to StageVariables. GuCDK will simplify this.
6682 DomainName :
6783 Type : String
6884 Description : The domain name of the ELB, should contain the trailing dot stuff.zone.example.com.
85+
6986Resources :
7087 DnsRecord :
7188 Type : AWS::Route53::RecordSet
@@ -77,6 +94,8 @@ Resources:
7794 TTL : 60
7895 Type : CNAME
7996
97+ # Ophan is the only consumer of this service, does it make so many requests that we have to horizontally scale?
98+ # TODO check with MSS and remove
8099 HighCpuAlarm :
81100 Type : AWS::CloudWatch::Alarm
82101 Properties :
@@ -96,6 +115,8 @@ Resources:
96115 Statistic : Average
97116 Threshold : !FindInMap [ StageVariables, !Ref Stage, ScalingUpThreshold ]
98117
118+ # Ophan is the only consumer of this service, does it make so many requests that we have to horizontally scale?
119+ # TODO check with MSS and remove
99120 LowCpuAlarm :
100121 Type : AWS::CloudWatch::Alarm
101122 Properties :
@@ -157,11 +178,16 @@ Resources:
157178 Type : AWS::EC2::SecurityGroup
158179 Properties :
159180 GroupDescription : Open up HTTP access to load balancer
181+
182+ # TODO
183+ # - restrict this to the ASG?
184+ # - Check what egress rules CDK would add to the load balancer
160185 SecurityGroupEgress :
161186 - CidrIp : 0.0.0.0/0
162187 FromPort : 9000
163188 IpProtocol : tcp
164189 ToPort : 9000
190+
165191 SecurityGroupIngress :
166192 - CidrIp : 0.0.0.0/0
167193 FromPort : 443
@@ -192,22 +218,29 @@ Resources:
192218 - PolicyName : root
193219 PolicyDocument :
194220 Statement :
221+ # To download the application artifact. GuCDK will tightly scope this.
195222 - Action : s3:GetObject
196223 Effect : Allow
197224 Resource : !Sub arn:aws:s3:::${DistBucket}/*
225+
198226 - Action : ec2:DescribeTags
199227 Effect : Allow
200228 Resource : ' *'
229+
230+ # TODO work out how these permissions are used by the application
201231 - Action :
202232 - cloudwatch:*
203233 - logs:*
204234 Effect : Allow
205235 Resource : ' *'
236+
206237 - Action :
207238 - autoscaling:DescribeAutoScalingInstances
208239 - autoscaling:DescribeAutoScalingGroups
209240 Resource : ' *'
210241 Effect : Allow
242+
243+ # To ship logs to Central ELK
211244 - Effect : Allow
212245 Action :
213246 - kinesis:PutRecord
@@ -217,11 +250,13 @@ Resources:
217250 - PolicyName : dynamo
218251 PolicyDocument :
219252 Statement :
220- - Action : dynamodb:*
253+ - Action : dynamodb:* # TODO tightly scope this (it allows for deletion 😱)
221254 Effect : Allow
222255 Resource :
223256 - !Sub arn:aws:dynamodb:eu-west-1:${AWS::AccountId}:table/mobile-notifications-reports-${Stage}
224257 - !Sub arn:aws:dynamodb:eu-west-1:${AWS::AccountId}:table/mobile-notifications-reports-${Stage}/index/*
258+
259+ # To read config from SSM
225260 - PolicyName : conf
226261 PolicyDocument :
227262 Statement :
@@ -243,11 +278,15 @@ Resources:
243278 - !Ref LoadBalancerToPrivateASG
244279 MaxSize : !Ref ASGMaxSize
245280 MinSize : !Ref ASGMinSize
281+
282+ # These currently go to the MSS team. GuCDK doesn't add this by default.
283+ # TODO check if the MSS team use the notifications. If they don't, remove this bit?
246284 NotificationConfiguration :
247285 NotificationTypes :
248286 - autoscaling:EC2_INSTANCE_LAUNCH_ERROR
249287 - autoscaling:EC2_INSTANCE_TERMINATE_ERROR
250288 TopicARN : !Sub arn:aws:sns:eu-west-1:${AWS::AccountId}:AutoscalingNotifications${Stage}
289+
251290 Tags :
252291 - Key : Stage
253292 PropagateAtLaunch : true
@@ -268,10 +307,15 @@ Resources:
268307 InstanceType : !FindInMap [StageVariables, !Ref Stage, InstanceType]
269308 SecurityGroups :
270309 - !Ref InstanceSecurityGroup
310+
311+ # TODO remove this
271312 - !Ref VPCSecurityGroup
272313 MetadataOptions :
273314 HttpTokens : required
274315 UserData :
316+
317+ # TODO replace configure-aws-kinesis-agent with devx-logs?
318+ # Log stream is stage aware.
275319 Fn::Base64 :
276320 !Sub
277321 - |
@@ -281,13 +325,19 @@ Resources:
281325 /opt/aws-kinesis-agent/configure-aws-kinesis-agent ${AWS::Region} mobile-log-aggregation-${Stage} /var/log/${App}/application.log
282326 - Stack : !FindInMap [Constants, Stack, Value]
283327 App : !FindInMap [Constants, App, Value]
328+
329+ # If we remove the CloudWatch Alarms above, these can also be removed.
330+ # TODO check with MSS and remove?
284331 ScaleDownPolicy :
285332 Type : AWS::AutoScaling::ScalingPolicy
286333 Properties :
287334 AdjustmentType : ChangeInCapacity
288335 AutoScalingGroupName : !Ref PrivateReportAutoscalingGroup
289336 Cooldown : 3600
290337 ScalingAdjustment : -1
338+
339+ # If we remove the CloudWatch Alarms above, these can also be removed.
340+ # TODO check with MSS and remove?
291341 ScaleUpPolicy :
292342 Type : AWS::AutoScaling::ScalingPolicy
293343 Properties :
0 commit comments