-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathcft.yml
786 lines (766 loc) · 23.8 KB
/
cft.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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
AWSTemplateFormatVersion: 2010-09-09
Parameters:
# Uncomment the network-related parameters if you wish to use your own predefined resources
# VPC:
# Type: 'AWS::EC2::VPC::Id'
# Description: Select a VPC that allows instances to access the Internet.
# PublicSubnetOne:
# Type: 'AWS::EC2::Subnet::Id'
# Description: Select a public subnet in your selected VPC.
# PublicSubnetTwo:
# Type: 'AWS::EC2::Subnet::Id'
# Description: Select one more public subnet in your selected VPC.
# PrivateSubnetOne:
# Type: 'AWS::EC2::Subnet::Id'
# Description: Select a private subnet in your selected VPC.
# PrivateSubnetTwo:
# Type: 'AWS::EC2::Subnet::Id'
# Description: Select another private subnet in your selected VPC .
ContainerCpu:
Type: Number
Default: 256
Description: How much CPU to give the container. 1024 is 1 CPU
ContainerMemory:
Type: Number
Default: 512
Description: How much memory in megabytes to give the container
SeleniumImageVersion:
Type: String
Default: 3.141.59
Description: >-
Version of the Selenium docker images - hub, node-chrome and node-firefox
- to be used.
Path:
Type: String
Default: '*'
Description: >-
A path on the public load balancer that this service should be connected
to. Use * to send all load balancer traffic to this service.
Priority:
Type: Number
Default: 1
Description: >-
The priority for the routing rule added to the load balancer. This only
applies if your have multiple services which have been assigned to
different paths on the load balancer.
Role:
Type: String
Default: ''
Description: >-
(Optional) An IAM role to give the service's containers if the code within
needs to access other AWS resources like S3 buckets, DynamoDB tables, etc
Conditions:
HasCustomRole: !Not
- !Equals
- !Ref Role
- ''
Mappings:
SubnetConfig:
VPC:
CIDR: 10.0.0.0/16
PublicOne:
CIDR: 10.0.0.0/24
PublicTwo:
CIDR: 10.0.1.0/24
PrivateOne:
CIDR: 10.0.2.0/24
PrivateTwo:
CIDR: 10.0.3.0/24
Resources:
# VPC in which containers will be networked.
# It has two public subnets, and two private subnets.
# We distribute the subnets across the first two available subnets
# for the region, for high availability.
VPC:
Type: 'AWS::EC2::VPC'
Properties:
EnableDnsSupport: true
EnableDnsHostnames: true
CidrBlock: !FindInMap
- SubnetConfig
- VPC
- CIDR
PublicSubnetOne:
Type: 'AWS::EC2::Subnet'
Properties:
AvailabilityZone:
'Fn::Select':
- 0
- 'Fn::GetAZs':
Ref: 'AWS::Region'
VpcId: !Ref VPC
CidrBlock: !FindInMap
- SubnetConfig
- PublicOne
- CIDR
MapPublicIpOnLaunch: true
PublicSubnetTwo:
Type: 'AWS::EC2::Subnet'
Properties:
AvailabilityZone:
'Fn::Select':
- 1
- 'Fn::GetAZs':
Ref: 'AWS::Region'
VpcId: !Ref VPC
CidrBlock: !FindInMap
- SubnetConfig
- PublicTwo
- CIDR
MapPublicIpOnLaunch: true
# Two private subnets where containers will only have private
# IP addresses, and will only be reachable by other members of the
# VPC
PrivateSubnetOne:
Type: 'AWS::EC2::Subnet'
Properties:
AvailabilityZone:
'Fn::Select':
- 0
- 'Fn::GetAZs':
Ref: 'AWS::Region'
VpcId: !Ref VPC
CidrBlock: !FindInMap
- SubnetConfig
- PrivateOne
- CIDR
PrivateSubnetTwo:
Type: 'AWS::EC2::Subnet'
Properties:
AvailabilityZone:
'Fn::Select':
- 1
- 'Fn::GetAZs':
Ref: 'AWS::Region'
VpcId: !Ref VPC
CidrBlock: !FindInMap
- SubnetConfig
- PrivateTwo
- CIDR
# Setup networking resources for the public subnets. Containers
# in the public subnets have public IP addresses and the routing table
# sends network traffic via the internet gateway.
InternetGateway:
Type: 'AWS::EC2::InternetGateway'
GatewayAttachement:
Type: 'AWS::EC2::VPCGatewayAttachment'
Properties:
VpcId: !Ref VPC
InternetGatewayId: !Ref InternetGateway
PublicRouteTable:
Type: 'AWS::EC2::RouteTable'
Properties:
VpcId: !Ref VPC
PublicRoute:
Type: 'AWS::EC2::Route'
DependsOn: GatewayAttachement
Properties:
RouteTableId: !Ref PublicRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
PublicSubnetOneRouteTableAssociation:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
SubnetId: !Ref PublicSubnetOne
RouteTableId: !Ref PublicRouteTable
PublicSubnetTwoRouteTableAssociation:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
SubnetId: !Ref PublicSubnetTwo
RouteTableId: !Ref PublicRouteTable
# Setup networking resources for the private subnets. Containers
# in these subnets have only private IP addresses, and must use a NAT
# gateway to talk to the internet. We launch two NAT gateways, one for
# each private subnet.
NatGatewayOneAttachment:
Type: 'AWS::EC2::EIP'
DependsOn: GatewayAttachement
Properties:
Domain: vpc
NatGatewayTwoAttachment:
Type: 'AWS::EC2::EIP'
DependsOn: GatewayAttachement
Properties:
Domain: vpc
NatGatewayOne:
Type: 'AWS::EC2::NatGateway'
Properties:
AllocationId: !GetAtt
- NatGatewayOneAttachment
- AllocationId
SubnetId: !Ref PublicSubnetOne
NatGatewayTwo:
Type: 'AWS::EC2::NatGateway'
Properties:
AllocationId: !GetAtt
- NatGatewayTwoAttachment
- AllocationId
SubnetId: !Ref PublicSubnetTwo
PrivateRouteTableOne:
Type: 'AWS::EC2::RouteTable'
Properties:
VpcId: !Ref VPC
PrivateRouteOne:
Type: 'AWS::EC2::Route'
Properties:
RouteTableId: !Ref PrivateRouteTableOne
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref NatGatewayOne
PrivateRouteTableOneAssociation:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
RouteTableId: !Ref PrivateRouteTableOne
SubnetId: !Ref PrivateSubnetOne
PrivateRouteTableTwo:
Type: 'AWS::EC2::RouteTable'
Properties:
VpcId: !Ref VPC
PrivateRouteTwo:
Type: 'AWS::EC2::Route'
Properties:
RouteTableId: !Ref PrivateRouteTableTwo
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref NatGatewayTwo
PrivateRouteTableTwoAssociation:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
RouteTableId: !Ref PrivateRouteTableTwo
SubnetId: !Ref PrivateSubnetTwo
# ECS-Fargate Resources
SeleniumGrid:
Type: 'AWS::ECS::Cluster'
Properties:
ClusterName: selenium-grid
SeleniumGridContainerSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Access to the Fargate containers
VpcId: !Ref VPC
EcsSecurityGroupIngressFromPublicALB:
Type: 'AWS::EC2::SecurityGroupIngress'
Properties:
Description: Ingress from the public ALB
GroupId: !Ref SeleniumGridContainerSecurityGroup
IpProtocol: -1
SourceSecurityGroupId: !Ref SeleniumLoadBalancerSG
EcsSecurityGroupIngressFromSelf:
Type: 'AWS::EC2::SecurityGroupIngress'
Properties:
Description: Ingress from other containers in the same security group
GroupId: !Ref SeleniumGridContainerSecurityGroup
IpProtocol: -1
SourceSecurityGroupId: !Ref SeleniumGridContainerSecurityGroup
# A public facing load balancer, this is used for accepting traffic from the public
# internet and directing it to public facing containers
SeleniumLoadBalancerSG:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Access to the public facing load balancer
VpcId: !Ref VPC
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
IpProtocol: -1
SeleniumLoadBalancer:
Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer'
Properties:
Scheme: internet-facing
LoadBalancerAttributes:
- Key: idle_timeout.timeout_seconds
Value: '100'
# The load balancer is placed into the public subnets, so that traffic
# from the internet can reach the load balancer directly via the internet gateway
Subnets:
- !Ref PublicSubnetOne
- !Ref PublicSubnetTwo
SecurityGroups:
- !Ref SeleniumLoadBalancerSG
DummyTargetGroupPublic:
Type: 'AWS::ElasticLoadBalancingV2::TargetGroup'
Properties:
HealthCheckIntervalSeconds: 6
HealthCheckPath: /
HealthCheckProtocol: HTTP
HealthCheckTimeoutSeconds: 5
HealthyThresholdCount: 2
Name: !Join
- '-'
- - !Ref 'AWS::StackName'
- drop-1
Port: 4444
Protocol: HTTP
UnhealthyThresholdCount: 2
VpcId: !Ref VPC
SeleniumLoadBalancerListener:
Type: 'AWS::ElasticLoadBalancingV2::Listener'
DependsOn: SeleniumLoadBalancer
Properties:
DefaultActions:
- TargetGroupArn: !Ref DummyTargetGroupPublic
Type: forward
LoadBalancerArn: !Ref SeleniumLoadBalancer
Port: 4444
Protocol: HTTP
# This is an IAM role which authorizes ECS to manage resources on your
# account on your behalf, such as updating your load balancer with the
# details of where your containers are, so that traffic can reach your
# containers.
ECSRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service:
- ecs.amazonaws.com
Action:
- 'sts:AssumeRole'
Path: /
Policies:
- PolicyName: ecs-service
PolicyDocument:
Statement:
- Effect: Allow
Action:
# Rules which allow ECS to attach network interfaces to instances
# on your behalf in order for awsvpc networking mode to work right
- 'ec2:AttachNetworkInterface'
- 'ec2:CreateNetworkInterface'
- 'ec2:CreateNetworkInterfacePermission'
- 'ec2:DeleteNetworkInterface'
- 'ec2:DeleteNetworkInterfacePermission'
- 'ec2:Describe*'
- 'ec2:DetachNetworkInterface'
# Rules which allow ECS to update load balancers on your behalf
# with the information sabout how to send traffic to your containers
- 'elasticloadbalancing:DeregisterInstancesFromLoadBalancer'
- 'elasticloadbalancing:DeregisterTargets'
- 'elasticloadbalancing:Describe*'
- 'elasticloadbalancing:RegisterInstancesWithLoadBalancer'
- 'elasticloadbalancing:RegisterTargets'
Resource: '*'
# This is a role which is used by the ECS tasks themselves.
ECSTaskExecutionRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service:
- ecs-tasks.amazonaws.com
Action:
- 'sts:AssumeRole'
Path: /
Policies:
- PolicyName: AmazonECSTaskExecutionRolePolicy
PolicyDocument:
Statement:
- Effect: Allow
Action:
# Allow the ECS Tasks to download images from ECR
- 'ecr:GetAuthorizationToken'
- 'ecr:BatchCheckLayerAvailability'
- 'ecr:GetDownloadUrlForLayer'
- 'ecr:BatchGetImage'
# Allow the ECS tasks to upload logs to CloudWatch
- 'logs:CreateLogStream'
- 'logs:CreateLogGroup'
- 'logs:DescribeLogGroups'
- 'logs:DescribeLogStreams'
- 'logs:PutLogEvents'
Resource: '*'
LogGroup:
Type: 'AWS::Logs::LogGroup'
Properties:
LogGroupName: selenium-grid
RetentionInDays: 30
TaskDefinitionHub:
Type: 'AWS::ECS::TaskDefinition'
Properties:
Cpu: !Ref ContainerCpu
Memory: !Ref ContainerMemory
NetworkMode: awsvpc
RequiresCompatibilities:
- FARGATE
ExecutionRoleArn: !GetAtt
- ECSTaskExecutionRole
- Arn
ContainerDefinitions:
- Name: selenium-hub
Cpu: !Ref ContainerCpu
Memory: !Ref ContainerMemory
Image: !Join
- ':'
- - 'selenium/hub'
- !Ref SeleniumImageVersion
Environment:
- Name: SE_OPTS
Value: '-debug'
- Name: GRID_TIMEOUT
Value: '180'
- Name: GRID_BROWSER_TIMEOUT
Value: '200000'
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group: !Ref LogGroup
awslogs-region: !Ref 'AWS::Region'
awslogs-stream-prefix: selenium-logs
PortMappings:
- ContainerPort: 4444
TaskDefinitionNodeChrome:
Type: 'AWS::ECS::TaskDefinition'
Properties:
Cpu: !Ref ContainerCpu
Memory: !Ref ContainerMemory
NetworkMode: awsvpc
RequiresCompatibilities:
- FARGATE
ExecutionRoleArn: !GetAtt
- ECSTaskExecutionRole
- Arn
ContainerDefinitions:
- Name: selenium-node-chrome
Cpu: !Ref ContainerCpu
Memory: !Ref ContainerMemory
Image: !Join
- ':'
- - 'selenium/node-chrome'
- !Ref SeleniumImageVersion
Environment:
- Name: HUB_PORT_4444_TCP_ADDR
Value: !GetAtt
- SeleniumLoadBalancer
- DNSName
- Name: HUB_PORT_4444_TCP_PORT
Value: '4444'
- Name: NODE_MAX_INSTANCES
Value: '5'
- Name: NODE_MAX_SESSION
Value: '5'
- Name: shm_size
Value: 512
- Name: SE_OPTS
Value: '-debug'
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group: !Ref LogGroup
awslogs-region: !Ref 'AWS::Region'
awslogs-stream-prefix: selenium-logs
EntryPoint:
- sh
- '-c'
Command:
- >-
PRIVATE=$(curl -s http://169.254.170.2/v2/metadata | jq -r
'.Containers[1].Networks[0].IPv4Addresses[0]') ; export
REMOTE_HOST="http://$PRIVATE:5555" ; /opt/bin/entry_point.sh
TaskDefinitionNodeFirefox:
Type: 'AWS::ECS::TaskDefinition'
Properties:
Cpu: !Ref ContainerCpu
Memory: !Ref ContainerMemory
NetworkMode: awsvpc
RequiresCompatibilities:
- FARGATE
ExecutionRoleArn: !GetAtt
- ECSTaskExecutionRole
- Arn
ContainerDefinitions:
- Name: selenium-node-firefox
Cpu: !Ref ContainerCpu
Memory: !Ref ContainerMemory
Image: !Join
- ':'
- - 'selenium/node-firefox'
- !Ref SeleniumImageVersion
Environment:
- Name: HUB_PORT_4444_TCP_ADDR
Value: !GetAtt
- SeleniumLoadBalancer
- DNSName
- Name: HUB_PORT_4444_TCP_PORT
Value: '4444'
- Name: NODE_MAX_INSTANCES
Value: '5'
- Name: NODE_MAX_SESSION
Value: '5'
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group: !Ref LogGroup
awslogs-region: !Ref 'AWS::Region'
awslogs-stream-prefix: selenium-logs
EntryPoint:
- sh
- '-c'
Command:
- >-
PRIVATE=$(curl -s http://169.254.170.2/v2/metadata | jq -r
'.Containers[1].Networks[0].IPv4Addresses[0]') ; export
REMOTE_HOST="http://$PRIVATE:5555" ; /opt/bin/entry_point.sh
ServiceHub:
Type: 'AWS::ECS::Service'
DependsOn: LoadBalancerRule
Properties:
ServiceName: selenium-hub-service
Cluster: !Ref SeleniumGrid
LaunchType: FARGATE
DeploymentConfiguration:
MaximumPercent: 200
MinimumHealthyPercent: 75
DesiredCount: 1
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: ENABLED
SecurityGroups:
- !Ref SeleniumGridContainerSecurityGroup
Subnets:
- !Ref PrivateSubnetOne
- !Ref PrivateSubnetTwo
TaskDefinition: !Ref TaskDefinitionHub
Role: !If
- HasCustomRole
- !Ref Role
- !Ref 'AWS::NoValue'
LoadBalancers:
- ContainerName: selenium-hub
ContainerPort: 4444
TargetGroupArn: !Ref SeleniumGridTargetGroup
ServiceNodeChrome:
Type: 'AWS::ECS::Service'
DependsOn: ServiceHub
Properties:
ServiceName: node-chrome
Cluster: !Ref SeleniumGrid
LaunchType: FARGATE
DeploymentConfiguration:
MaximumPercent: 200
MinimumHealthyPercent: 75
DesiredCount: 2
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: ENABLED
SecurityGroups:
- !Ref SeleniumGridContainerSecurityGroup
Subnets:
- !Ref PrivateSubnetOne
- !Ref PrivateSubnetTwo
TaskDefinition: !Ref TaskDefinitionNodeChrome
ServiceNodeFirefox:
Type: 'AWS::ECS::Service'
DependsOn: ServiceHub
Properties:
ServiceName: node-firefox
Cluster: !Ref SeleniumGrid
LaunchType: FARGATE
DeploymentConfiguration:
MaximumPercent: 200
MinimumHealthyPercent: 75
DesiredCount: 2
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: ENABLED
SecurityGroups:
- !Ref SeleniumGridContainerSecurityGroup
Subnets:
- !Ref PrivateSubnetOne
- !Ref PrivateSubnetTwo
TaskDefinition: !Ref TaskDefinitionNodeFirefox
SeleniumGridTargetGroup:
Type: 'AWS::ElasticLoadBalancingV2::TargetGroup'
Properties:
HealthCheckIntervalSeconds: 6
HealthCheckPath: /
HealthCheckProtocol: HTTP
HealthCheckTimeoutSeconds: 5
HealthyThresholdCount: 2
TargetType: ip
Name: selenium-grid
Port: 4444
Protocol: HTTP
UnhealthyThresholdCount: 2
VpcId: !Ref VPC
LoadBalancerRule:
Type: 'AWS::ElasticLoadBalancingV2::ListenerRule'
DependsOn: SeleniumLoadBalancerListener
Properties:
Actions:
- TargetGroupArn: !Ref SeleniumGridTargetGroup
Type: forward
Conditions:
- Field: path-pattern
Values:
- !Ref Path
ListenerArn: !Ref SeleniumLoadBalancerListener
Priority: !Ref Priority
# Resources for auto-scaling browser clusters
AutoscalingRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service:
- application-autoscaling.amazonaws.com
Action:
- 'sts:AssumeRole'
Path: /
Policies:
- PolicyName: service-autoscaling
PolicyDocument:
Statement:
- Effect: Allow
Action:
- 'application-autoscaling:*'
- 'cloudwatch:DescribeAlarms'
- 'cloudwatch:PutMetricAlarm'
- 'ecs:DescribeServices'
- 'ecs:UpdateService'
Resource: '*'
FirefoxScalableTarget:
Type: 'AWS::ApplicationAutoScaling::ScalableTarget'
DependsOn: ServiceNodeFirefox
Properties:
ResourceId: !Join
- /
- - service
- !Ref SeleniumGrid
- !GetAtt
- ServiceNodeFirefox
- Name
ServiceNamespace: ecs
ScalableDimension: 'ecs:service:DesiredCount'
RoleARN: !GetAtt
- AutoscalingRole
- Arn
MaxCapacity: '4'
MinCapacity: '0'
FirefoxServiceScaleOutPolicy:
Type: 'AWS::ApplicationAutoScaling::ScalingPolicy'
DependsOn: FirefoxScalableTarget
Properties:
PolicyName: autoscale_firefox_service
PolicyType: StepScaling
ScalingTargetId: !Ref FirefoxScalableTarget
StepScalingPolicyConfiguration:
AdjustmentType: ChangeInCapacity
Cooldown: 180
MetricAggregationType: Average
StepAdjustments:
- ScalingAdjustment: 2
MetricIntervalLowerBound: 0
ChromeScalableTarget:
Type: 'AWS::ApplicationAutoScaling::ScalableTarget'
DependsOn: ServiceNodeChrome
Properties:
ResourceId: !Join
- /
- - service
- !Ref SeleniumGrid
- !GetAtt
- ServiceNodeChrome
- Name
ServiceNamespace: ecs
ScalableDimension: 'ecs:service:DesiredCount'
RoleARN: !GetAtt
- AutoscalingRole
- Arn
MaxCapacity: '36'
MinCapacity: '0'
ChromeServiceScaleOutPolicy:
Type: 'AWS::ApplicationAutoScaling::ScalingPolicy'
DependsOn: ChromeScalableTarget
Properties:
PolicyName: autoscale_chrome_service
PolicyType: StepScaling
ScalingTargetId: !Ref ChromeScalableTarget
StepScalingPolicyConfiguration:
AdjustmentType: ChangeInCapacity
Cooldown: 180
MetricAggregationType: Average
StepAdjustments:
- ScalingAdjustment: 1
MetricIntervalLowerBound: 0
NodeServiceCPUScaleOutAlarm:
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmName: SELENIUM_FARGATE_NODE_CPU_80PCT_1MIN_DEV
EvaluationPeriods: '1'
Statistic: Maximum
TreatMissingData: missing
Threshold: '80'
AlarmDescription: Alarm to add capacity if CPU is high
Period: 60
AlarmActions:
- !Ref FirefoxServiceScaleOutPolicy
- !Ref ChromeServiceScaleOutPolicy
Namespace: AWS/ECS
Dimensions:
- Name: ClusterName
Value: !Ref SeleniumGrid
- Name: ServiceName
Value: !GetAtt
- ServiceNodeFirefox
- Name
ComparisonOperator: GreaterThanOrEqualToThreshold
MetricName: CPUUtilization
NodeServiceMemoryScaleOutAlarm:
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmName: SELENIUM_FARGATE_NODE_MEMORY_80PCT_1MIN_DEV
EvaluationPeriods: '1'
Statistic: Maximum
TreatMissingData: missing
Threshold: '80'
AlarmDescription: Alarm to add capacity if MEMORY is high
Period: 60
AlarmActions:
- !Ref FirefoxServiceScaleOutPolicy
- !Ref ChromeServiceScaleOutPolicy
Namespace: AWS/ECS
Dimensions:
- Name: ClusterName
Value: !Ref SeleniumGrid
- Name: ServiceName
Value: !GetAtt
- ServiceNodeFirefox
- Name
ComparisonOperator: GreaterThanOrEqualToThreshold
MetricName: MemoryUtilization
# Optional
# RecordSet:
# Type: 'AWS::Route53::RecordSetGroup'
# DependsOn: SeleniumLoadBalancer
# Properties:
# HostedZoneId: !GetAtt
# - SeleniumLoadBalancer
# - CanonicalHostedZoneID
# RecordSets:
# - Name: !Join
# - .
# - - selenium-grid
# - !Ref DomainName
# Type: CNAME
# TTL: '300'
# ResourceRecords:
# - !GetAtt
# - SeleniumLoadBalancer
# - DNSName
Outputs:
ExternalUrl:
Description: The url of the external load balancer
Value: !Join
- ''
- - 'http://'
- !GetAtt
- SeleniumLoadBalancer
- DNSName
Export:
Name: !Join
- ':'
- - !Ref 'AWS::StackName'
- ExternalUrl