-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdeep-learning-ubuntu-desktop.yaml
executable file
·1246 lines (1135 loc) · 43 KB
/
deep-learning-ubuntu-desktop.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
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
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
AWSTemplateFormatVersion: 2010-09-09
Description: >-
AWS Deep Learning Ubuntu Desktop with DCV Server.
Connect using a DCV Client.
Parameters:
AWSUbuntuAMIType:
Description: Ubuntu Pro 22.04 LTS, Ubuntu Pro 20.04 LTS.
Type: String
Default: "UbuntuPro2204LTS"
AllowedValues:
- "UbuntuPro2004LTS"
- "UbuntuPro2204LTS"
S3Bucket:
Description: S3 bucket name for read write access from desktop
Type: String
S3Import:
Description: >-
(Optional) Advanced option to specify S3 import prefix for FSx file-system.
See FSxForLustre parameter to enable FSx for Lustre file-system.
Type: String
Default: ""
UbuntuAMIOverride:
Description: >-
(Optional) Advanced option to override the Ubuntu 20.04 or 22.04 AMI.
Leave blank, if unsure.
Type: String
AllowedPattern: '(ami-[0-9a-z]{17})?'
DesktopVpcId:
Description: Desktop VPC ID
Type: 'AWS::EC2::VPC::Id'
DesktopVpcSubnetId:
Description: Desktop VPC Subnet ID. Subnet must be public with IGW access, if DesktopHasPublicIpAddress is 'true', else private with NAT gateway access.
Type: 'AWS::EC2::Subnet::Id'
DesktopHasPublicIpAddress:
Description: Should a Public Ip Address be associated with the Desktop?
Type: String
Default: "true"
AllowedValues:
- "true"
- "false"
EbsVolumeSize:
Default: 500
Description: Ebs volume size (GB)
Type: Number
MinValue: 500
EbsVolumeType:
Default: 'gp3'
Description: Ebs volume type
Type: String
AllowedValues:
- 'gp2'
- 'gp3'
EFSFileSystemId:
Description: >-
(Optional) Advanced option to specify an
existing EFS File System Id with an existing mount target in your subnet.
Leave blank to create a new EFS file system.
Type: String
AllowedPattern: '(^fs-[0-9a-f]+)$|()$'
Default: ''
ConstraintDescription: Should be a Valid EFS File System Id, or blank
EFSMountPath:
Description: EFS file-system mount directory path.
Type: String
Default: '/home/ubuntu/efs'
ConstraintDescription: Should be a valid file-system directory path
DesktopSecurityGroupId:
Description: >-
(Optional) Advanced option to specify existing Desktop Security Group Id.
Leave blank to create new Security Group.
Type: String
AllowedPattern: '(^sg-[0-9a-z]+)$|()$'
Default: ''
ConstraintDescription: Should be a Valid SecurityGroup Id in selected VPC, or blank
FSxCapacity:
Description: Must be a multiple of 1200 GBs
Type: Number
Default: 1200
MinValue: 1200
FSxForLustre:
Description: >-
Advanced option to enable, disable FSx for Lustre file-system.
The FSx for Lustre file-system
automatically imports data from s3://S3bucket/S3Import.
See S3Bucket and S3Import parameters.
Type: String
Default: 'disabled'
AllowedValues:
- 'enabled'
- 'disabled'
FSxMountPath:
Description: FSx file-system mount directory path.
Type: String
Default: '/home/ubuntu/fsx'
ConstraintDescription: Should be a valid file-system directory path
FSxLustreVersion:
Description: FSx file-system type version
Type: String
Default: '2.15'
ConstraintDescription: Should be a valid FSx for Lustre version
KeyName:
Description: >-
Name of an existing Amazon EC2 KeyPair to enable SSH and DCV access to the
desktop
Type: 'AWS::EC2::KeyPair::KeyName'
DesktopInstanceType:
Description: EC2 instance type for desktop
Type: String
Default: g6.xlarge
AllowedValues:
- m5d.2xlarge
- m5d.4xlarge
- m5d.8xlarge
- m5d.12xlarge
- m5d.16xlarge
- m5d.24xlarge
- m5n.24xlarge
- m5dn.24xlarge
- r5d.2xlarge
- r5d.4xlarge
- r5d.8xlarge
- r5d.12xlarge
- r5d.16xlarge
- r5d.24xlarge
- r5n.24xlarge
- r5dn.24xlarge
- c5d.2xlarge
- c5d.4xlarge
- c5d.9xlarge
- c5n.9xlarge
- c5d.12xlarge
- c5d.18xlarge
- c5n.18xlarge
- c5d.24xlarge
- g3s.xlarge
- g3.4xlarge
- g3.8xlarge
- g3.16xlarge
- g4dn.xlarge
- g4dn.2xlarge
- g4dn.4xlarge
- g4dn.8xlarge
- g4dn.12xlarge
- g4dn.16xlarge
- g5.xlarge
- g5.2xlarge
- g5.4xlarge
- g5.8xlarge
- g5.12xlarge
- g5.16xlarge
- g5.24xlarge
- g5.48xlarge
- g6.xlarge
- g6.2xlarge
- g6.4xlarge
- g6.8xlarge
- g6.12xlarge
- g6.16xlarge
- g6.24xlarge
- g6.48xlarge
- g6e.xlarge
- g6e.2xlarge
- g6e.4xlarge
- g6e.8xlarge
- g6e.12xlarge
- g6e.16xlarge
- g6e.24xlarge
- g6e.48xlarge
- p3.2xlarge
- p3.8xlarge
- p3.16xlarge
- p3dn.24xlarge
- p4d.24xlarge
- trn1.2xlarge
- trn1.32xlarge
- trn1n.32xlarge
- inf2.xlarge
- inf2.8xlarge
- inf2.24xlarge
- inf2.48xlarge
ConstraintDescription: Must be a valid CPU, or GPU instance type.
DesktopAccessCIDR:
Description: >-
Restrict desktop access for SSH and DCV client from a valid CIDR range
Type: String
MinLength: '9'
MaxLength: '18'
AllowedPattern: '(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})'
ConstraintDescription: Must be a valid CIDR range of the form x.x.x.x/x
EBSOptimized:
Description: >-
Is the instance EBS optimized?
Type: String
Default: 'true'
AllowedValues:
- 'false'
- 'true'
Mappings:
UbuntuPro2004LTS:
us-east-1:
AMI: ami-0c7167c7f19b42827
us-east-2:
AMI: ami-0cb8bd12ae00545d8
us-west-2:
AMI: ami-08a6c204633ef5cee
eu-west-1:
AMI: ami-0adab63e5043085d1
eu-central-1:
AMI: ami-0a7314af79e1386c7
ap-southeast-1:
AMI: ami-0b489de3fab3a7e3b
ap-southeast-2:
AMI: ami-03a8bb8234272744b
ap-south-1:
AMI: ami-009c3d26336b8d5c4
ap-northeast-1:
AMI: ami-0df434ac8f8cdeb9f
ap-northeast-2:
AMI: ami-02acd68454c0247e4
UbuntuPro2204LTS:
us-east-1:
AMI: ami-005fc0f236362e99f
us-east-2:
AMI: ami-00eb69d236edcfaf8
us-west-2:
AMI: ami-0b8c6b923777519db
eu-west-1:
AMI: ami-0a422d70f727fe93e
eu-central-1:
AMI: ami-0745b7d4092315796
ap-southeast-1:
AMI: ami-03fa85deedfcac80b
ap-southeast-2:
AMI: ami-040e71e7b8391cae4
ap-south-1:
AMI: ami-09b0a86a2c84101e1
ap-northeast-1:
AMI: ami-0ac6b9b2908f3e20d
ap-northeast-2:
AMI: ami-042e76978adeb8c48
Conditions:
OverrideAMI: !Not
- !Equals
- !Ref UbuntuAMIOverride
- ''
CreateNewEFSFileSystem: !Equals
- !Ref EFSFileSystemId
- ''
FSxForLustreEnabled: !Equals
- !Ref FSxForLustre
- 'enabled'
CreateNewSecurityGroup: !Equals
- !Ref DesktopSecurityGroupId
- ''
EfaCpuInstances: !Or
- !Equals
- !Ref DesktopInstanceType
- 'm5n.24xlarge'
- !Equals
- !Ref DesktopInstanceType
- 'm5dn.24xlarge'
- !Equals
- !Ref DesktopInstanceType
- 'c5n.9xlarge'
- !Equals
- !Ref DesktopInstanceType
- 'c5n.18xlarge'
- !Equals
- !Ref DesktopInstanceType
- 'r5n.24xlarge'
- !Equals
- !Ref DesktopInstanceType
- 'r5dn.24xlarge'
EfaGInstances: !Or
- !Equals
- !Ref DesktopInstanceType
- 'g4dn.8xlarge'
- !Equals
- !Ref DesktopInstanceType
- 'g4dn.12xlarge'
- !Equals
- !Ref DesktopInstanceType
- 'g4dn.16xlarge'
- !Equals
- !Ref DesktopInstanceType
- 'g5.8xlarge'
- !Equals
- !Ref DesktopInstanceType
- 'g5.12xlarge'
- !Equals
- !Ref DesktopInstanceType
- 'g5.16xlarge'
- !Equals
- !Ref DesktopInstanceType
- 'g5.24xlarge'
- !Equals
- !Ref DesktopInstanceType
- 'g5.48xlarge'
EfaG6eInstances: !Or
- !Equals
- !Ref DesktopInstanceType
- 'g6e.12xlarge'
- !Equals
- !Ref DesktopInstanceType
- 'g6e.16xlarge'
- !Equals
- !Ref DesktopInstanceType
- 'g6e.24xlarge'
- !Equals
- !Ref DesktopInstanceType
- 'g6e.48xlarge'
EfaPInstances: !Or
- !Equals
- !Ref DesktopInstanceType
- 'p4d.24xlarge'
- !Equals
- !Ref DesktopInstanceType
- 'p3dn.24xlarge'
EfaTrn132Instances: !Or
- !Equals
- !Ref DesktopInstanceType
- 'trn1.32xlarge'
- !Equals
- !Ref DesktopInstanceType
- 'trn1n.32xlarge'
EfaEnabled: !Or
- !Condition EfaCpuInstances
- !Condition EfaGInstances
- !Condition EfaG6eInstances
- !Condition EfaPInstances
- !Condition EfaTrn132Instances
Resources:
DesktopSecurityGroup:
Condition: CreateNewSecurityGroup
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Desktop security group
VpcId: !Ref DesktopVpcId
Tags:
- Key: Name
Value: !Ref 'AWS::StackName'
DesktopSecurityGroupCIDRIngressDCV:
Condition: CreateNewSecurityGroup
Type: 'AWS::EC2::SecurityGroupIngress'
Properties:
Description: Ingress from CIDR for NICE-DCV access to graphics desktop
GroupId: !GetAtt DesktopSecurityGroup.GroupId
CidrIp: !Ref DesktopAccessCIDR
IpProtocol: tcp
FromPort: 8443
ToPort: 8443
DesktopSecurityGroupCIDRIngressSSH:
Condition: CreateNewSecurityGroup
Type: 'AWS::EC2::SecurityGroupIngress'
Properties:
Description: Ingress from CIDR for SSH access to graphics desktop
GroupId: !GetAtt DesktopSecurityGroup.GroupId
CidrIp: !Ref DesktopAccessCIDR
IpProtocol: tcp
FromPort: 22
ToPort: 22
DesktopSecurityGroupIngressSelf:
Condition: CreateNewSecurityGroup
Type: 'AWS::EC2::SecurityGroupIngress'
Properties:
Description: Ingress from self security group
GroupId: !GetAtt DesktopSecurityGroup.GroupId
IpProtocol: "-1"
FromPort: 0
ToPort: 65535
SourceSecurityGroupId: !GetAtt DesktopSecurityGroup.GroupId
DesktopSecurityGroupEgressSelf:
Condition: CreateNewSecurityGroup
Type: 'AWS::EC2::SecurityGroupEgress'
Properties:
Description: Egress to self security group
GroupId: !GetAtt DesktopSecurityGroup.GroupId
IpProtocol: "-1"
FromPort: 0
ToPort: 65535
DestinationSecurityGroupId: !GetAtt DesktopSecurityGroup.GroupId
DesktopSecurityGroupCIDREgress:
Condition: CreateNewSecurityGroup
Type: 'AWS::EC2::SecurityGroupEgress'
Properties:
Description: Egress rule for out bound traffic
GroupId: !GetAtt DesktopSecurityGroup.GroupId
IpProtocol: tcp
FromPort: 0
ToPort: 65535
CidrIp: '0.0.0.0/0'
EFSFileSystem:
Type: 'AWS::EFS::FileSystem'
Condition: CreateNewEFSFileSystem
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Properties:
Encrypted : true
PerformanceMode: generalPurpose
FileSystemTags:
- Key: Name
Value: !Ref 'AWS::StackName'
EFSMountTarget:
Condition: CreateNewEFSFileSystem
Type: 'AWS::EFS::MountTarget'
Properties:
FileSystemId: !Ref EFSFileSystem
SubnetId: !Ref DesktopVpcSubnetId
SecurityGroups:
- !GetAtt EFSSecurityGroup.GroupId
EFSSecurityGroup:
Condition: CreateNewEFSFileSystem
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Security group for EFS mount target
VpcId: !Ref DesktopVpcId
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 2049
ToPort: 2049
SourceSecurityGroupId: !If
- CreateNewSecurityGroup
- !GetAtt DesktopSecurityGroup.GroupId
- !Ref DesktopSecurityGroupId
Description: Ingress from desktop
SecurityGroupEgress:
- IpProtocol: tcp
FromPort: 2049
ToPort: 2049
DestinationSecurityGroupId: !If
- CreateNewSecurityGroup
- !GetAtt DesktopSecurityGroup.GroupId
- !Ref DesktopSecurityGroupId
Description: Egress to desktop
EFSSecurityGroupIngress:
Condition: CreateNewEFSFileSystem
Type: 'AWS::EC2::SecurityGroupIngress'
Properties:
Description: Ingress from within the EFSSecurityGroup
GroupId: !GetAtt EFSSecurityGroup.GroupId
IpProtocol: tcp
FromPort: 2049
ToPort: 2049
SourceSecurityGroupId: !GetAtt EFSSecurityGroup.GroupId
EFSSecurityGroupEgress:
Condition: CreateNewEFSFileSystem
Type: 'AWS::EC2::SecurityGroupEgress'
Properties:
Description: Ingress from within the EFSSecurityGroup
GroupId: !GetAtt EFSSecurityGroup.GroupId
IpProtocol: tcp
FromPort: 2049
ToPort: 2049
DestinationSecurityGroupId: !GetAtt EFSSecurityGroup.GroupId
FSxSecurityGroup:
Condition: FSxForLustreEnabled
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Security group for FSx mount target
VpcId: !Ref DesktopVpcId
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 988
ToPort: 988
SourceSecurityGroupId: !If
- CreateNewSecurityGroup
- !GetAtt DesktopSecurityGroup.GroupId
- !Ref DesktopSecurityGroupId
Description: Ingress from desktop
SecurityGroupEgress:
- IpProtocol: tcp
FromPort: 988
ToPort: 988
DestinationSecurityGroupId: !If
- CreateNewSecurityGroup
- !GetAtt DesktopSecurityGroup.GroupId
- !Ref DesktopSecurityGroupId
Description: Egress to desktop
FSxSecurityGroupIngress:
Condition: FSxForLustreEnabled
Type: 'AWS::EC2::SecurityGroupIngress'
Properties:
Description: Ingress from within the FSxSecurityGroup
GroupId: !GetAtt FSxSecurityGroup.GroupId
IpProtocol: tcp
FromPort: 988
ToPort: 988
SourceSecurityGroupId: !GetAtt FSxSecurityGroup.GroupId
FSxSecurityGroupEgress:
Condition: FSxForLustreEnabled
Type: 'AWS::EC2::SecurityGroupEgress'
Properties:
Description: Ingress from within the FSxSecurityGroup
GroupId: !GetAtt FSxSecurityGroup.GroupId
IpProtocol: tcp
FromPort: 988
ToPort: 988
DestinationSecurityGroupId: !GetAtt FSxSecurityGroup.GroupId
FSxFileSystem:
Condition: FSxForLustreEnabled
Type: AWS::FSx::FileSystem
Properties:
FileSystemType: 'LUSTRE'
FileSystemTypeVersion: !Ref FSxLustreVersion
LustreConfiguration:
DeploymentType: SCRATCH_2
AutoImportPolicy: NEW_CHANGED
ImportPath: !Sub s3://${S3Bucket}/${S3Import}
SecurityGroupIds:
- !GetAtt FSxSecurityGroup.GroupId
StorageCapacity: !Ref FSxCapacity
StorageType: 'SSD'
SubnetIds:
- !Ref DesktopVpcSubnetId
Tags:
- Key: Name
Value: !Ref 'AWS::StackName'
InstanceRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
- sagemaker.amazonaws.com
Action:
- 'sts:AssumeRole'
Path: /
ManagedPolicyArns:
- !Sub 'arn:${AWS::Partition}:iam::aws:policy/AmazonSageMakerFullAccess'
Policies:
- PolicyName: s3-read-write
PolicyDocument:
Statement:
- Effect: Allow
Action:
- "s3:Get*"
- "s3:List*"
- "s3:PutObject*"
- "s3:DeleteObject*"
Resource:
- !Sub 'arn:aws:s3:::${S3Bucket}'
- !Sub 'arn:aws:s3:::${S3Bucket}/*'
- PolicyName: dcv-license-s3
PolicyDocument:
Statement:
- Effect: Allow
Action:
- 's3:GetObject'
Resource:
- !Sub 'arn:aws:s3:::dcv-license.${AWS::Region}/*'
- PolicyName: ec2-autoscaling
PolicyDocument:
Statement:
- Effect: Allow
Action:
- 'autoscaling:DescribeAutoScalingInstances'
- 'ec2:DescribeInstances'
Resource: '*'
- PolicyName: ecr-policy
PolicyDocument:
Statement:
- Effect: Allow
Action:
- "ecr:SetRepositoryPolicy"
- "ecr:CompleteLayerUpload"
- "ecr:BatchDeleteImage"
- "ecr:UploadLayerPart"
- "ecr:DeleteRepositoryPolicy"
- "ecr:InitiateLayerUpload"
- "ecr:DeleteRepository"
- "ecr:PutImage"
Resource: '*'
InstanceProfile:
Type: 'AWS::IAM::InstanceProfile'
Properties:
Path: /
Roles:
- !Ref InstanceRole
DesktopLaunchTemplate:
Type: AWS::EC2::LaunchTemplate
Properties:
LaunchTemplateData:
MetadataOptions:
HttpTokens: "required"
HttpEndpoint: "enabled"
NetworkInterfaces:
- AssociatePublicIpAddress: !Ref DesktopHasPublicIpAddress
DeviceIndex: "0"
Groups:
- !If
- CreateNewSecurityGroup
- !GetAtt DesktopSecurityGroup.GroupId
- !Ref DesktopSecurityGroupId
SubnetId: !Ref DesktopVpcSubnetId
BlockDeviceMappings:
- DeviceName: "/dev/sda1"
Ebs:
VolumeSize: !Ref EbsVolumeSize
VolumeType: !Ref EbsVolumeType
Encrypted: true
DeleteOnTermination: true
ImageId: !If
- OverrideAMI
- !Ref UbuntuAMIOverride
- !FindInMap
- !Ref 'AWSUbuntuAMIType'
- !Ref 'AWS::Region'
- AMI
EbsOptimized: !Ref EBSOptimized
EfaDesktopLaunchTemplate:
Condition: EfaEnabled
Type: AWS::EC2::LaunchTemplate
Properties:
LaunchTemplateData:
MetadataOptions:
HttpTokens: "required"
HttpEndpoint: "enabled"
NetworkInterfaces:
- AssociatePublicIpAddress: !Ref DesktopHasPublicIpAddress
Description: NetworkInterfaces Configuration For EFA
NetworkCardIndex: 0
DeviceIndex: 0
DeleteOnTermination: true
Groups:
- !If
- CreateNewSecurityGroup
- !GetAtt DesktopSecurityGroup.GroupId
- !Ref DesktopSecurityGroupId
SubnetId: !Ref DesktopVpcSubnetId
InterfaceType: efa
BlockDeviceMappings:
- DeviceName: "/dev/sda1"
Ebs:
VolumeSize: !Ref EbsVolumeSize
VolumeType: !Ref EbsVolumeType
Encrypted: true
DeleteOnTermination: true
ImageId: !If
- OverrideAMI
- !Ref UbuntuAMIOverride
- !FindInMap
- !Ref 'AWSUbuntuAMIType'
- !Ref 'AWS::Region'
- AMI
EbsOptimized: !Ref EBSOptimized
DesktopInstance:
Type: 'AWS::EC2::Instance'
Properties:
LaunchTemplate:
LaunchTemplateId: !If
- EfaEnabled
- !Ref EfaDesktopLaunchTemplate
- !Ref DesktopLaunchTemplate
Version: !GetAtt DesktopLaunchTemplate.LatestVersionNumber
InstanceType: !Ref DesktopInstanceType
IamInstanceProfile: !Ref InstanceProfile
KeyName: !Ref KeyName
Tags:
- Key: "Name"
Value: !Sub '${AWS::StackName}-deep-learning-ubuntu-desktop'
UserData: !Base64
'Fn::Join':
- ''
- - |
Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0
--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"
#cloud-config
cloud_final_modules:
- [scripts-user, always]
--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"
#!/bin/bash -xe
echo "Cloud init in progress!" > /etc/motd
. /etc/os-release
distro=ubuntu${VERSION_ID//[.]/""}
arch="x86_64"
echo "Ubuntu $distro/$arch"
# setup graphics desktop
export DEBIAN_FRONTEND=noninteractive
export DEBCONF_NONINTERACTIVE_SEEN=true
dpkg -l | grep linux | awk -F' ' '{print $2}' > /tmp/dpkg.out
for pkg in `cat /tmp/dpkg.out`; do apt-mark hold $pkg; done
CUDA=12.4
CUDA_DASH=${CUDA//\./-}
CUDA_11=11.8
CUDA_11_DASH=${CUDA_11//\./-}
- OVERRIDE_AMI=
- !Ref UbuntuAMIOverride
- |+
if [[ -z "${OVERRIDE_AMI}" ]]; then
[[ ! -z $(lspci -v | grep NVIDIA) ]] && \
[[ ! -x "$(command -v nvidia-smi)" ]] && \
apt-get -y install linux-headers-$(uname -r) && \
wget https://developer.download.nvidia.com/compute/cuda/repos/$distro/$arch/cuda-keyring_1.1-1_all.deb && \
dpkg -i cuda-keyring_1.1-1_all.deb && \
apt-get update && apt-get -y purge cuda && apt-get -y purge nvidia-* && apt-get -y purge libnvidia-* && apt-get -y autoremove && \
apt-get -y install cuda-${CUDA_DASH} && \
apt-get -y install cuda-${CUDA_11_DASH} && \
apt-get -y install libcudnn8 && \
apt-get -y install libcudnn8-dev && \
echo "export PATH=/usr/local/cuda-${CUDA}/bin:/usr/local/cuda-${CUDA_11}/bin:$PATH" >> /home/ubuntu/.bashrc && \
CUDA_COMPAT=$(nvidia-smi | grep CUDA | awk '{print $(NF - 1)}') && \
CUDA_COMPAT_DASH=${CUDA_COMPAT//\./-} && \
apt-get -y install cuda-compat-${CUDA_COMPAT_DASH} && \
echo "export LD_LIBRARY_PATH=/usr/local/cuda-${CUDA_COMPAT}/compat:/usr/local/cuda-${CUDA}/lib64:$LD_LIBRARY_PATH" >> /home/ubuntu/.bashrc && \
reboot
dpkg -l | grep nvidia | awk -F' ' '{print $2}' > /tmp/dpkg.out
for pkg in `cat /tmp/dpkg.out`; do apt-mark hold $pkg; done
[[ -z $(lspci -v | grep NVIDIA) ]] && update-pciids
if ( [[ ! -z $(lspci -v | grep Trainium) ]] || [[ ! -z $(lspci -v | grep Inferentia2) ]] ) \
&& [[ ! -x "$(command -v /opt/aws/neuron/neuron-ls)" ]]
then
wget -qO - https://apt.repos.neuron.amazonaws.com/GPG-PUB-KEY-AMAZON-AWS-NEURON.PUB > ./GPG-PUB-KEY-AMAZON-AWS-NEURON.PUB
gpg --no-default-keyring --keyring ./aws_neuron_keyring.gpg --import ./GPG-PUB-KEY-AMAZON-AWS-NEURON.PUB
gpg --no-default-keyring --keyring ./aws_neuron_keyring.gpg --export > ./aws_neuron.gpg
mv ./aws_neuron.gpg /etc/apt/trusted.gpg.d/
rm ./GPG-PUB-KEY-AMAZON-AWS-NEURON.PUB
add-apt-repository -y "deb https://apt.repos.neuron.amazonaws.com ${VERSION_CODENAME} main"
apt-get -y update
apt-get -y install linux-headers-$(uname -r) git
apt-get -y install aws-neuronx-dkms aws-neuronx-oci-hook aws-neuronx-collectives aws-neuronx-runtime-lib aws-neuronx-tools
echo "export PATH=/opt/aws/neuron/bin:$PATH" >> /home/ubuntu/.bashrc
fi
fi
# setup software repo for docker
wget -qO - https://download.docker.com/linux/ubuntu/gpg > ./GPG_DOCKER.PUB
gpg --no-default-keyring --keyring ./docker_keyring.gpg --import ./GPG_DOCKER.PUB
gpg --no-default-keyring --keyring ./docker_keyring.gpg --export > ./docker.gpg
mv ./docker.gpg /etc/apt/trusted.gpg.d/
rm ./GPG_DOCKER.PUB
add-apt-repository -y "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# setup software repo for fsx-lustre client
wget -qO - https://fsx-lustre-client-repo-public-keys.s3.amazonaws.com/fsx-ubuntu-public-key.asc > ./fsx-ubuntu-public-key.asc
gpg --no-default-keyring --keyring ./fsx_keyring.gpg --import ./fsx-ubuntu-public-key.asc
gpg --no-default-keyring --keyring ./fsx_keyring.gpg --export > ./fsx.gpg
mv ./fsx.gpg /etc/apt/trusted.gpg.d/
rm ./fsx-ubuntu-public-key.asc
# add key for NICE-DCV
wget -qO - https://d1uj6qtbmh3dt5.cloudfront.net/NICE-GPG-KEY > ./NICE-GPG-KEY
gpg --no-default-keyring --keyring ./nice_dcv_keyring.gpg --import ./NICE-GPG-KEY
gpg --no-default-keyring --keyring ./nice_dcv_keyring.gpg --export > ./nice_dcv.gpg
mv ./nice_dcv.gpg /etc/apt/trusted.gpg.d/
rm ./NICE-GPG-KEY
# add visual code repository
wget -qO - https://packages.microsoft.com/keys/microsoft.asc > ./microsoft.asc
gpg --no-default-keyring --keyring ./microsoft_keyring.gpg --import ./microsoft.asc
gpg --no-default-keyring --keyring ./microsoft_keyring.gpg --export > ./microsoft.gpg
mv ./microsoft.gpg /etc/apt/trusted.gpg.d/
rm ./microsoft.asc
add-apt-repository -y "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"
# update and install required packages
apt-get update
apt-get -y install git tar
apt-get -y install software-properties-common
# install docker if it is not installed
if [ ! -x "$(command -v docker)" ]; then
apt-get -y install docker-ce docker-ce-cli containerd.io
usermod -aG docker ubuntu
# install nvidia container toolkit if we have a nvidia GPU
if [[ -x "$(command -v nvidia-smi)" ]]
then
wget -qO - https://nvidia.github.io/nvidia-container-runtime/gpgkey > ./gpg_nvidia_container_runtime.pub
gpg --no-default-keyring --keyring ./nvidia_container_runtime_keyring.gpg --import ./gpg_nvidia_container_runtime.pub
gpg --no-default-keyring --keyring ./nvidia_container_runtime_keyring.gpg --export > ./nvidia_container_runtime.gpg
mv ./nvidia_container_runtime.gpg /etc/apt/trusted.gpg.d/
rm ./gpg_nvidia_container_runtime.pub
distribution=$ID$VERSION_ID
curl -s -L https://nvidia.github.io/nvidia-container-runtime/$distribution/nvidia-container-runtime.list | \
tee /etc/apt/sources.list.d/nvidia-container-runtime.list
apt-get update
apt-get -y install nvidia-container-toolkit
fi
fi
apt-get -y install tzdata
apt-get -y install keyboard-configuration
apt-get -y install gnupg2
apt-get -y install lsb-core
apt-get -y install openmpi-bin libopenmpi-dev
apt-get -y install protobuf-compiler
# install DCV server
echo "install DCV server..."
apt-get -y install ubuntu-desktop
if [[ "$VERSION_ID" == 20.04* ]]
then
add-apt-repository -y "deb https://fsx-lustre-client-repo.s3.amazonaws.com/ubuntu focal main"
if [[ ! -x "$(command -v dcv)" ]]
then
apt-get -y install gdm3
echo "/usr/sbin/gdm3" > /etc/X11/default-display-manager
dpkg-reconfigure gdm3
sed -i -e "s/#WaylandEnable=false/WaylandEnable=false/g" /etc/gdm3/custom.conf
systemctl restart gdm3
apt-get -y install mesa-utils
if [[ -x "$(command -v nvidia-xconfig)" ]] && [[ -x "$(command -v nvidia-smi)" ]]
then
nvidia-xconfig --preserve-busid --enable-all-gpus
fi
#restart X server
echo "restart X-server"
systemctl set-default graphical.target
systemctl isolate graphical.target
wget https://d1uj6qtbmh3dt5.cloudfront.net/2024.0/Servers/nice-dcv-2024.0-18131-ubuntu2004-x86_64.tgz
tar -xvzf nice-dcv-2024.0-18131-ubuntu2004-x86_64.tgz
cd nice-dcv-2024.0-18131-ubuntu2004-x86_64
apt-get -y install ./nice-dcv-server_2024.0.18131-1_amd64.ubuntu2004.deb
reboot
fi
elif [[ "$VERSION_ID" == 22.04* ]]
then
add-apt-repository -y "deb https://fsx-lustre-client-repo.s3.amazonaws.com/ubuntu jammy main"
if [[ ! -x "$(command -v dcv)" ]]
then
apt-get -y install gdm3
echo "/usr/sbin/gdm3" > /etc/X11/default-display-manager
dpkg-reconfigure gdm3
sed -i -e "s/#WaylandEnable=false/WaylandEnable=false/g" /etc/gdm3/custom.conf
systemctl restart gdm3
apt-get -y install mesa-utils
if [[ -x "$(command -v nvidia-xconfig)" ]] && [[ -x "$(command -v nvidia-smi)" ]]
then
nvidia-xconfig --preserve-busid --enable-all-gpus
fi
#restart X server
echo "restart X-server"
systemctl set-default graphical.target
systemctl isolate graphical.target
wget https://d1uj6qtbmh3dt5.cloudfront.net/2024.0/Servers/nice-dcv-2024.0-18131-ubuntu2204-x86_64.tgz
tar -xvzf nice-dcv-2024.0-18131-ubuntu2204-x86_64.tgz
cd nice-dcv-2024.0-18131-ubuntu2204-x86_64
apt-get -y install ./nice-dcv-server_2024.0.18131-1_amd64.ubuntu2204.deb
reboot
fi
else
echo "Ubuntu $VERSION_ID is not supported; must be one of 20.04, or 22.04"
exit 1
fi
#restart X server
systemctl set-default graphical.target
systemctl isolate graphical.target
# Create DCV server configuration file
[[ -d /opt/dcv-session-store ]] || mkdir /opt/dcv-session-store
echo "[license]" >> dcv.conf
echo "[log]" >> dcv.conf
echo "[session-management]" >> dcv.conf
echo "create-session = true" >> dcv.conf
echo "[session-management/defaults]" >> dcv.conf
echo "[session-management/automatic-console-session]" >> dcv.conf
echo "owner=ubuntu" >> dcv.conf
echo "storage-root=\"/opt/dcv-session-store/\"" >> dcv.conf
echo "[display]" >> dcv.conf
echo "[connectivity]" >> dcv.conf
echo "[security]" >> dcv.conf
echo "authentication=\"system\"" >> dcv.conf
echo "[clipboard]" >> dcv.conf
echo "primary-selection-copy=true" >> dcv.conf
echo "primary-selection-paste=true" >> dcv.conf
mv dcv.conf /etc/dcv/dcv.conf
# Create DCV session permissions files
rm -f /home/ubuntu/dcv.perms
echo "[permissions]" >> /home/ubuntu/dcv.perms
echo "%owner% allow builtin" >> /home/ubuntu/dcv.perms
# Enable DCV server
systemctl enable dcvserver
systemctl restart dcvserver
echo "install DCV server complete"
# install nfs-common
apt-get -y install nfs-common
- AWS_REGION=
- !Ref AWS::Region
- |+
- EFS_FS_ID=
- !If
- CreateNewEFSFileSystem
- !Ref EFSFileSystem
- !Ref EFSFileSystemId
- |+
- EFS_MOUNT_PATH=
- !Ref EFSMountPath
- |+
- FSX_MOUNT_PATH=
- !Ref FSxMountPath
- |+
- DESKTOP_ROLE_ARN=
- !GetAtt InstanceRole.Arn
- |+
- DESKTOP_SUBNET_ID=
- !Ref DesktopVpcSubnetId
- |+
- DESKTOP_SG_ID=
- !If
- CreateNewSecurityGroup
- !GetAtt DesktopSecurityGroup.GroupId
- !Ref DesktopSecurityGroupId
- |+
- FSX_ENABLED=
- !If
- FSxForLustreEnabled
- "true"
- "false"
- |+
- FSX_FS_ID=
- !If