-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfree_arm64_template.yaml
377 lines (352 loc) · 11.8 KB
/
free_arm64_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
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
AWSTemplateFormatVersion: "2010-09-09"
Transform: "AWS::Serverless-2016-10-31"
Description: Cribl LogStream Worker Deployment (arm64)
Parameters:
criblCloudLeader:
Description: "REQUIRED: Cribl Cloud Leader node name. Please do not include https:// in the hostname. "
Type: String
criblclusterAuthToken:
Description: "REQUIRED: Token from Cribl Cloud Leader node."
Type: String
NoEcho: True
workerGroup:
Description: "Cribl Worker Group for Cribl LogStream Cloud deployment. It is set to default unless you change it."
Type: String
Default: default
workerCount:
Description: "REQUIRED: Enter the number of worker nodes desired"
Type: String
vpcId:
Description: "REQUIRED: ID of your existing VPC."
Type: AWS::EC2::VPC::Id
subnetIds:
Description: "REQUIRED: Select 2 subnet Ids in different AZs. These subnets must be in the same VPC as VPC ID above."
Type: List<AWS::EC2::Subnet::Id>
ImageId:
Description: "REQUIRED: Name of the AMI for the EC2 Instance being used for your Cribl Deployment."
Type: AWS::EC2::Image::Id
workerInstanceType:
Description: EC2 instance type to provision the LogStream worker instance. If none specified, c6g.xlarge will be used.
Type: String
Default: c6g.xlarge
AllowedValues:
- t4g.micro
- t4g.nano
- t4g.small
- t4g.medium
- t4g.large
- t4g.xlarge
- c6g.large
- c6g.4xlarge
- c6gd.large
- c6gd.xlarge
- c6gd.2xlarge
- c6gd.4xlarge
- m6g.medium
- m6g.large
- m6g.xlarge
- m7g.large
- m7g.xlarge
- c7gn.medium
- c7gn.large
- c7gn.xlarge
- c7gn.4xlarge
- c7g.large
- c7g.2xlarge
- c7g.4xlarge
- m7gd.large
- m7gd.xlarge
- m7gd.4xlarge
ConstraintDescription: Must contain valid instance type
AdditionalPolicies:
Default: "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore,arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"
Description: A comma separated list of Policy ARNs to add to the IAM role used by Logstream instances. Append to defaults, DO NOT REMOVE!
Type: CommaDelimitedList
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Cribl LogStream Cloud Information
Parameters:
- criblCloudLeader
- criblclusterAuthToken
- workerGroup
- Label:
default: Worker Instance Configuration
Parameters:
- workerInstanceType
- workerCount
- Label:
default: Network Configuration
Parameters:
- vpcId
- subnetIds
- Label:
default: Advanced Settings
Parameters:
- AdditionalPolicies
ParameterLabels:
criblCloudLeader:
default: Cribl LogStream Cloud Leader node hostname
criblclusterAuthToken:
default: Cribl LogStream Cloud authentication key
workerGroup:
default: Cribl worker node group name
workerInstanceType:
default: Worker Nodes EC2 Instance Type
workerCount:
default: Worker Count
vpcId:
default: VPC ID
subnetIds:
default: Subnet IDs
AdditionalPolicies:
default: IAM Policies for node instance profiles
Rules:
SubnetsInVPC:
Assertions:
- Assert: !EachMemberIn
- !ValueOfAll
- AWS::EC2::Subnet::Id
- VpcId
- !RefAll "AWS::EC2::VPC::Id"
AssertDescription: All subnets must in the VPC
Resources:
ec2WorkerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Cribl LogStream Access
VpcId: !Ref vpcId
SecurityGroupEgress:
- IpProtocol: "-1"
CidrIp: 0.0.0.0/0
Description: Egress access
s3DefaultDestinationBucket:
Type: AWS::S3::Bucket
Properties:
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
Tags:
- Key: Name
Value: Cribl LogStream default destination bucket
LogstreamRole:
Type: AWS::IAM::Role
Properties:
Path: !Sub "/logstream/${AWS::StackName}/"
Description: Cribl LogStream IAM role
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns: !Ref AdditionalPolicies
Policies:
- PolicyName: S3Destinations
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- s3:PutObject
- s3:GetObject
- s3:ListBucket
- s3:GetBucketLocation
Resource:
- !Sub ${s3DefaultDestinationBucket.Arn}
- !Sub ${s3DefaultDestinationBucket.Arn}/*
- PolicyName: S3Sources
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- s3:GetObject
- s3:GetBucketLocation
Resource:
- !Sub ${s3DefaultDestinationBucket.Arn}
- !Sub ${s3DefaultDestinationBucket.Arn}/*
- PolicyName: KinesisSources
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- kinesis:GetRecords
- kinesis:GetShardIterator
- kinesis:ListShards
NotResource: "*"
- PolicyName: SecretsManagerRead
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- secretsmanager:GetSecretValue
Resource:
- !Ref clusterAuthToken
Tags:
- Key: Name
Value: Cribl LogStream default IAM role
LogstreamInstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Path: !Sub "/logstream/${AWS::StackName}/"
Roles:
- !Ref LogstreamRole
clusterAuthToken:
Type: 'AWS::SecretsManager::Secret'
Properties:
Description: "Cribl Logstream Cluster Auth Token"
SecretString: !Ref criblclusterAuthToken
ec2WorkersAutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
DesiredCapacity: !Ref workerCount
MaxSize: !Ref workerCount
MinSize: !Ref workerCount
HealthCheckType: EC2
LaunchTemplate:
LaunchTemplateId: !Ref ec2WorkerslaunchTemplate
Version: !GetAtt ec2WorkerslaunchTemplate.LatestVersionNumber
VPCZoneIdentifier:
- !Select [0, !Ref subnetIds]
- !Select [1, !Ref subnetIds]
Tags:
- Key: Name
Value: Cribl LogStream Worker Nodes ASG
PropagateAtLaunch: false
ec2WorkersAutoScalingGroupLifecycleHook:
Type: AWS::AutoScaling::LifecycleHook
Properties:
AutoScalingGroupName: !Ref ec2WorkersAutoScalingGroup
DefaultResult: ABANDON
HeartbeatTimeout: 3600
LifecycleHookName: cribl-logstream-worker-shutdown
LifecycleTransition: "autoscaling:EC2_INSTANCE_TERMINATING"
ec2WorkerslaunchTemplate:
Type: AWS::EC2::LaunchTemplate
Properties:
LaunchTemplateData:
InstanceInitiatedShutdownBehavior: terminate
ImageId: !Ref ImageId
InstanceType: !Ref workerInstanceType
IamInstanceProfile:
Arn: !GetAtt LogstreamInstanceProfile.Arn
SecurityGroupIds:
- !Ref ec2WorkerSecurityGroup
UserData: !Base64
Fn::Sub:
- |
#cloud-config
runcmd:
- export AWS_DEFAULT_REGION=${Region}
- /usr/local/bin/configure_logstream.sh -m worker -u ${clusterAuthToken} -H ${ec2leaderInstanceIp} -g ${workerGroup}
- ec2leaderInstanceIp: !Ref criblCloudLeader
clusterAuthToken: !Ref clusterAuthToken
Region: !Ref AWS::Region
TagSpecifications:
- ResourceType: instance
Tags:
- Key: Name
Value: Cribl LogStream Worker Instance
workerShutdownEventRule:
Type: AWS::Events::Rule
Properties:
Description: "Cribl LogStream Worker Shutdown Event"
EventPattern:
source:
- "aws.autoscaling"
detail-type:
- "EC2 Instance-terminate Lifecycle Action"
detail:
AutoScalingGroupName:
- !Ref ec2WorkersAutoScalingGroup
State: "ENABLED"
Targets:
- Arn: !GetAtt functionWorkerShutdown.Arn
Id: "WorkerShutdownFunction"
lamdbaPermissionWorkerShutdownEventRule:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref functionWorkerShutdown
Action: "lambda:InvokeFunction"
Principal: "events.amazonaws.com"
SourceArn: !GetAtt workerShutdownEventRule.Arn
functionWorkerShutdown:
Type: AWS::Serverless::Function
Properties:
Description: Cribl LogStream Worker Shutdown
InlineCode: |
import boto3
import logging
import json
import time
import os
ssm = boto3.client('ssm')
autoscaling = boto3.client('autoscaling')
# Logging
log = logging.getLogger()
log.setLevel(logging.DEBUG)
def handler(event, context):
log.debug("Received event {}".format(json.dumps(event)))
command = ssm.send_command(
InstanceIds=[event['detail']['EC2InstanceId'],],
DocumentName='AWS-RunShellScript',
Comment='Gracefully terminate Cribl LogStream worker node',
Parameters={"commands":["systemctl disable cribl","systemctl daemon-reload","systemctl stop cribl"],"workingDirectory":[""],"executionTimeout":["3600"]},
CloudWatchOutputConfig={
'CloudWatchOutputEnabled': True
}
)
command_id = command['Command']['CommandId']
for x in range(0,59):
time.sleep(10)
response = ssm.get_command_invocation(
CommandId=command_id,
InstanceId=event['detail']['EC2InstanceId'],
)
if response.get('Status') == 'Success':
break
else:
continue
autoscaling.complete_lifecycle_action(
LifecycleHookName=event['detail']['LifecycleHookName'],
AutoScalingGroupName=event['detail']['AutoScalingGroupName'],
LifecycleActionToken=event['detail']['LifecycleActionToken'],
LifecycleActionResult='CONTINUE',
InstanceId=event['detail']['EC2InstanceId']
)
Policies:
- Statement:
- Action: ["ssm:SendCommand"]
Effect: Allow
Resource: "*"
Condition:
StringEquals:
"aws:ResourceTag/aws:ec2launchtemplate:id": !Ref ec2WorkerslaunchTemplate
- Action: ["ssm:SendCommand"]
Effect: Allow
Resource: !Sub "arn:${AWS::Partition}:ssm:${AWS::Region}::document/AWS-RunShellScript"
- Action: ["autoscaling:CompleteLifecycleAction"]
Effect: Allow
Resource: !Sub "arn:${AWS::Partition}:autoscaling:${AWS::Region}:${AWS::AccountId}:autoScalingGroup:*:autoScalingGroupName/${ec2WorkersAutoScalingGroup}"
- Action: ["ssm:GetCommandInvocation"]
Effect: Allow
Resource: "*"
Runtime: python3.12
Timeout: 600
Handler: index.handler
Outputs:
logstreamWebUrlPublic:
Value: !Sub https://cribl.cloud
Description: Cribl Cloud LogStream Login
stackName:
Value: !Sub "${AWS::StackName}"
Description: CFN Stack Name