-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfree_x86_64_template.yaml
717 lines (668 loc) · 22.5 KB
/
free_x86_64_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
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
AWSTemplateFormatVersion: "2010-09-09"
Transform: "AWS::Serverless-2016-10-31"
Description: Cribl Stream Free Distributed Deployment (x86_64)
Parameters:
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
ImageId:
Description: "REQUIRED: Name of the AMI for the EC2 Instance being used for your Cribl Deployment."
Type: AWS::EC2::Image::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>
webAccessCidr:
Type: String
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/x
Description: "REQUIRED: The CIDR IP range permitted to access the Cribl Stream web console. We recommend you set this value to a trusted IP range."
leaderInstanceType:
Description: EC2 instance type to provision the Cribl Stream leader instance. If none specified, c5a.xlarge will be used.
Type: String
Default: c5a.xlarge
AllowedValues:
- t2.small
- t2.medium
- t2.large
- t2.xlarge
- t3.small
- t3.medium
- t3.large
- t3.xlarge
- t3a.small
- t3a.medium
- t3a.large
- c5.large
- c5.xlarge
- c5d.large
- c5d.xlarge
- c5a.large
- c5a.xlarge
- c5ad.large
- c5ad.xlarge
- c5n.large
- c5n.xlarge
- m5a.large
- m5a.xlarge
- m5ad.large
- m5ad.xlarge
- m5d.large
- m5d.xlarge
ConstraintDescription: Must contain valid instance type
workerInstanceType:
Description: EC2 instance type to provision the Cribl Stream worker instance. If none specified, c5a.xlarge will be used.
Type: String
Default: c5a.xlarge
AllowedValues:
- t2.small
- t2.medium
- t2.large
- t2.xlarge
- t3.small
- t3.medium
- t3.large
- t3.xlarge
- t3a.small
- t3a.medium
- t3a.large
- c5.large
- c5.xlarge
- c5d.large
- c5d.xlarge
- c5a.large
- c5a.xlarge
- c5ad.large
- c5ad.xlarge
- c5n.large
- c5n.xlarge
- m5a.large
- m5a.xlarge
- m5a.2xlarge
- m5ad.large
- m5ad.xlarge
- m5d.large
- m5d.xlarge
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: leader Instance Configuration
Parameters:
- leaderInstanceType
- Label:
default: Worker Instance Configuration
Parameters:
- workerInstanceType
- workerCount
- Label:
default: Network Configuration
Parameters:
- vpcId
- subnetIds
- webAccessCidr
- Label:
default: Advanced Settings
Parameters:
- AdditionalPolicies
ParameterLabels:
leaderInstanceType:
default: leader Node EC2 Instance Type
workerInstanceType:
default: Worker Nodes EC2 Instance Type
workerCount:
default: Worker Count
vpcId:
default: VPC ID
subnetIds:
default: Subnet IDs
webAccessCidr:
default: Web Access CIDR
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:
ec2leaderSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Cribl Stream Access
VpcId: !Ref vpcId
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 9000
ToPort: 9000
CidrIp: !Ref webAccessCidr
Description: UI access to the Cribl Stream leader instance
- IpProtocol: tcp
FromPort: 4200
ToPort: 4200
CidrIp: !Ref webAccessCidr
#SourceSecurityGroupId: !GetAtt ec2WorkerSecurityGroup.GroupId
Description: Cluster communications between leader and workers
SecurityGroupEgress:
- IpProtocol: "-1"
CidrIp: 0.0.0.0/0
Description: Egress access
LeaderLoadBalancerExternal:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Type: application
Scheme: internet-facing
IpAddressType: ipv4
SecurityGroups:
- !Ref ec2leaderSecurityGroup
Subnets:
- !Select [0, !Ref 'subnetIds']
- !Select [1, !Ref 'subnetIds']
LeaderLoadBalancerInternal:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Type: network
LoadBalancerAttributes:
- Key: load_balancing.cross_zone.enabled
Value: "true"
Scheme: internal
IpAddressType: ipv4
Subnets:
- !Select [0, !Ref 'subnetIds']
- !Select [1, !Ref 'subnetIds']
LeaderCriblTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
DependsOn: LeaderLoadBalancerExternal
Properties:
HealthCheckPort: '9000'
HealthCheckProtocol: HTTP
Port: 9000
Protocol: HTTP
TargetType: instance
VpcId: !Ref vpcId
CriblLeaderWebListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: !Ref LeaderCriblTargetGroup
LoadBalancerArn: !Ref LeaderLoadBalancerExternal
Port: 9000
Protocol: HTTP
WorkerCriblTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
DependsOn: LeaderLoadBalancerInternal
Properties:
HealthCheckPort: '4200'
HealthCheckProtocol: TCP
Port: 4200
Protocol: TCP
TargetType: instance
VpcId: !Ref vpcId
CriblWorkerAdminListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: !Ref WorkerCriblTargetGroup
LoadBalancerArn: !Ref LeaderLoadBalancerInternal
Port: 4200
Protocol: TCP
WorkerCriblTCPJSONTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
DependsOn: LeaderLoadBalancerInternal
Properties:
HealthCheckPort: '10001'
HealthCheckProtocol: TCP
Port: 10001
Protocol: TCP
TargetType: instance
VpcId: !Ref vpcId
CriblWorkerTCPJSONListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: !Ref WorkerCriblTCPJSONTargetGroup
LoadBalancerArn: !Ref LeaderLoadBalancerInternal
Port: 10001
Protocol: TCP
WorkerCriblTCPRAWTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
DependsOn: LeaderLoadBalancerInternal
Properties:
HealthCheckPort: '7777'
HealthCheckProtocol: TCP
Port: 7777
Protocol: TCP
TargetType: instance
VpcId: !Ref vpcId
CriblWorkerTCPRAWListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: !Ref WorkerCriblTCPRAWTargetGroup
LoadBalancerArn: !Ref LeaderLoadBalancerInternal
Port: 7777
Protocol: TCP
CriblLeaderWebListenerRule1:
Type: AWS::ElasticLoadBalancingV2::ListenerRule
Properties:
Actions:
- Type: forward
TargetGroupArn: !Ref LeaderCriblTargetGroup
Conditions:
- Field: http-request-method
HttpRequestMethodConfig:
Values:
- GET_OR_HEAD
ListenerArn: !Ref CriblLeaderWebListener
Priority: 1
ec2WorkerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Cribl Stream Ingress and Egress for Ports
VpcId: !Ref vpcId
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 10001
ToPort: 10001
CidrIp: !Ref webAccessCidr
Description: TCP-raw Data Collection Ingress
- IpProtocol: tcp
FromPort: 7777
ToPort: 7777
CidrIp: !Ref webAccessCidr
Description: TCP-json Data Collection Ingress
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 Stream default destination bucket
LogstreamRole:
Type: AWS::IAM::Role
Properties:
Path: !Sub "/logstream/${AWS::StackName}/"
Description: Cribl Stream 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 Stream default IAM role
LogstreamInstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Path: !Sub "/logstream/${AWS::StackName}/"
Roles:
- !Ref LogstreamRole
ec2LeaderAutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
VPCZoneIdentifier:
- !Select [0, !Ref 'subnetIds']
- !Select [1, !Ref 'subnetIds']
TargetGroupARNs:
- !Ref LeaderCriblTargetGroup
- !Ref WorkerCriblTargetGroup
DesiredCapacity: "1"
MaxSize: "1"
MinSize: "0"
HealthCheckType: EC2
LaunchTemplate:
LaunchTemplateId: !Ref ec2leaderlaunchTemplate
Version: !GetAtt ec2leaderlaunchTemplate.LatestVersionNumber
Tags:
- Key: Name
Value: Cribl Stream Leader Nodes ASG
PropagateAtLaunch: false
ec2LeaderAutoScalingGroupLifecycleHook:
Type: AWS::AutoScaling::LifecycleHook
Properties:
AutoScalingGroupName: !Ref ec2LeaderAutoScalingGroup
DefaultResult: ABANDON
HeartbeatTimeout: 3600
LifecycleHookName: cribl-logstream-leader-shutdown
LifecycleTransition: "autoscaling:EC2_INSTANCE_TERMINATING"
ec2leaderlaunchTemplate:
Type: AWS::EC2::LaunchTemplate
Properties:
LaunchTemplateData:
InstanceInitiatedShutdownBehavior: terminate
ImageId: !Ref ImageId
InstanceType: !Ref leaderInstanceType
IamInstanceProfile:
Arn: !GetAtt LogstreamInstanceProfile.Arn
SecurityGroupIds:
- !Ref ec2leaderSecurityGroup
UserData: !Base64
Fn::Sub:
- |
#cloud-config
runcmd:
- export AWS_DEFAULT_REGION=${Region}
- /usr/local/bin/configure_logstream.sh -m master -b ${s3DefaultDestinationBucket} -u ${clusterAuthToken}
- sleep 10
- cloud-init query -f "$(cat /opt/cribl_build/users.json.j2)" > /opt/cribl/local/cribl/auth/users.json
- chown -R cribl:cribl /opt/cribl
- clusterAuthToken: !Ref clusterAuthToken
Region: !Ref AWS::Region
TagSpecifications:
- ResourceType: instance
Tags:
- Key: Name
Value: Cribl Stream Leader Node
leaderShutdownEventRule:
Type: AWS::Events::Rule
Properties:
Description: "Cribl Stream Leader Shutdown Event"
EventPattern:
source:
- "aws.autoscaling"
detail-type:
- "EC2 Instance-terminate Lifecycle Action"
detail:
AutoScalingGroupName:
- !Ref ec2LeaderAutoScalingGroup
State: "ENABLED"
Targets:
- Arn: !GetAtt functionLeaderShutdown.Arn
Id: "WorkerShutdownFunction"
lamdbaPermissionLeaderShutdownEventRule:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref functionLeaderShutdown
Action: "lambda:InvokeFunction"
Principal: "events.amazonaws.com"
SourceArn: !GetAtt workerShutdownEventRule.Arn
functionLeaderShutdown:
Type: AWS::Serverless::Function
Properties:
Description: Cribl Stream Leader 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 Stream leader 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 ec2leaderlaunchTemplate
- 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
clusterAuthToken:
Type: 'AWS::SecretsManager::Secret'
Properties:
Description: "Cribl Logstream Cluster Auth Token"
GenerateSecretString:
PasswordLength: 30
ExcludePunctuation: true
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 Stream 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 ${LeaderLoadBalancerInternal.DNSName} -p 4200
- sed -i 's/false/true/g' /opt/cribl/local/_system/instance.yml
- sleep 60
- systemctl restart cribl
- clusterAuthToken: !Ref clusterAuthToken
Region: !Ref AWS::Region
TagSpecifications:
- ResourceType: instance
Tags:
- Key: Name
Value: Cribl Stream Worker Instance
workerShutdownEventRule:
Type: AWS::Events::Rule
Properties:
Description: "Cribl Stream 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 Stream 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 Stream 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 http://${LeaderLoadBalancerExternal.DNSName}:9000/login
Description: Cribl Stream Web URL
logstreamWebAccessCreds:
Value: "admin / Leader EC2 Instance ID"
Description: Default Web Access Credentials