-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathbbb-on-aws-ecs.template.yaml
162 lines (148 loc) · 5.31 KB
/
bbb-on-aws-ecs.template.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
---
AWSTemplateFormatVersion: '2010-09-09'
Description: >
This Cloudformation Template deploys a private ECS Cluster for the BigBlueButton Frontend (Greenlight and Scalelite).
Disclaimer: Not for production use. Demo and testing purposes only.
Author: David Surey <[email protected]>
Parameters:
BBBNotificationTopic:
Description: Topic to be used for alarm notifications
Type: String
BBBECSInstanceType:
Description: Compute type for ECS Cluster (FARGATE or EC2 instance type, x86_64 only)
Type: String
Default: t3.large
AllowedPattern: ^(fargate|(t2|t3|t3a|m4|m5|m5a|m6i|c4|c5|c5a|c6i|r4|r5|r5a|r6i)\.(medium|large|xlarge|2xlarge|4xlarge|8xlarge|12xlarge|16xlarge|24xlarge))$
BBBECSMaxInstances:
Type: Number
Description: Maximum number of ECS Worker Instances
Default: 3
BBBECSMinInstances:
Type: Number
Description: Minimum number of ECS Worker Instances
Default: 1
BBBECSDesiredInstances:
Type: Number
Description: Desired number of ECS Worker Instances
Default: 1
BBBApplicationSubnets:
Description: Comma separated list of the private EC2 instance subnets
Type: CommaDelimitedList
BBBECSTaskSecurityGroup:
Description: Security Group that should be assigned for the EC2 Instances
Type: String
BBBLatestECSAmiId:
Description: AMI id that should be used for the EC2 instaces
Type: 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>'
Default: '/aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id'
Conditions:
BBBECSFargate: !Equals [!Ref BBBECSInstanceType, fargate]
BBBECSEC2: !Not [!Equals [!Ref BBBECSInstanceType, fargate]]
Resources:
BBBECSCluster:
Type: AWS::ECS::Cluster
Properties:
ClusterName: !Sub ${AWS::StackName}-ECSCluster
CapacityProviders:
- !If [ BBBECSFargate, FARGATE, !Ref BBBECSCapacityProvider ]
- !If [ BBBECSFargate, FARGATE_SPOT, !Ref "AWS::NoValue" ]
ClusterSettings:
- Name: containerInsights
Value: enabled
BBBECSCapacityProvider:
Type: AWS::ECS::CapacityProvider
Condition: BBBECSEC2
Properties:
AutoScalingGroupProvider:
AutoScalingGroupArn: !Ref BBBECSAutoScaling
ManagedScaling:
Status: ENABLED
MinimumScalingStepSize: !Ref BBBECSMinInstances
MaximumScalingStepSize: !Ref BBBECSMaxInstances
TargetCapacity: 90
ManagedTerminationProtection: DISABLED
BBBECSAutoScaling:
Type: AWS::AutoScaling::AutoScalingGroup
Condition: BBBECSEC2
Properties:
VPCZoneIdentifier: !Ref BBBApplicationSubnets
LaunchConfigurationName: !Ref BBBECSInstanceLaunchConfiguration
TerminationPolicies:
- DEFAULT
MaxSize: !Ref BBBECSMaxInstances
MinSize: !Ref BBBECSMinInstances
DesiredCapacity: !Ref BBBECSDesiredInstances
NotificationConfiguration:
TopicARN:
Ref: BBBNotificationTopic
NotificationTypes:
- autoscaling:EC2_INSTANCE_LAUNCH
- autoscaling:EC2_INSTANCE_LAUNCH_ERROR
- autoscaling:EC2_INSTANCE_TERMINATE
- autoscaling:EC2_INSTANCE_TERMINATE_ERROR
CreationPolicy:
ResourceSignal:
Timeout: PT15M
UpdatePolicy:
AutoScalingReplacingUpdate:
WillReplace: true
BBBECSEC2Role:
Type: AWS::IAM::Role
Condition: BBBECSEC2
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: [ec2.amazonaws.com]
Action: ["sts:AssumeRole"]
Path: /
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role
- arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
BBBECSEC2InstanceProfile:
Type: AWS::IAM::InstanceProfile
Condition: BBBECSEC2
Properties:
Path: /
Roles:
- !Ref BBBECSEC2Role
BBBECSInstanceLaunchConfiguration:
Type: AWS::AutoScaling::LaunchConfiguration
Condition: BBBECSEC2
Properties:
AssociatePublicIpAddress: false
IamInstanceProfile: !Ref BBBECSEC2InstanceProfile
ImageId: !Ref BBBLatestECSAmiId
EbsOptimized: false
InstanceMonitoring: true
InstanceType: !Ref BBBECSInstanceType
SecurityGroups:
- !Ref BBBECSTaskSecurityGroup
UserData:
Fn::Base64: !Sub |
#!/bin/bash -xe
echo ECS_CLUSTER=${AWS::StackName}-ECSCluster >> /etc/ecs/ecs.config
yum install -y aws-cfn-bootstrap
yum update -y ecs-init
/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource BBBECSAutoScaling --region ${AWS::Region}
Outputs:
BBBECSCluster:
Description: A reference to the created Cluster
Value: !Ref BBBECSCluster
BBBECSAutoScaling:
Description: A reference to the created Cluster Autoscaling Group
Value: !Ref BBBECSAutoScaling
Condition: BBBECSEC2
BBBECSEC2Role:
Description: A reference to the created Cluster Role
Value: !Ref BBBECSEC2Role
Condition: BBBECSEC2
BBBECSEC2InstanceProfile:
Description: A reference to the created Cluster Instance profile
Value: !Ref BBBECSEC2InstanceProfile
Condition: BBBECSEC2
BBBECSInstanceLaunchConfiguration:
Description: A reference to the created Cluster Launch Configuration
Value: !Ref BBBECSInstanceLaunchConfiguration
Condition: BBBECSEC2