-
Notifications
You must be signed in to change notification settings - Fork 9
/
cvat-aws-ap-northeast-1-all.yaml
1247 lines (1142 loc) · 37 KB
/
cvat-aws-ap-northeast-1-all.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
Description: This template deploys a CVAT on AWS ECS Fargate.
Parameters:
VpcCIDR:
Description: Please enter the IP range (CIDR notation) for this VPC
Type: String
Default: 10.192.0.0/16
PublicSubnet1CIDR:
Description: Please enter the IP range (CIDR notation) for the public subnet in the first Availability Zone
Type: String
Default: 10.192.10.0/24
PublicSubnet2CIDR:
Description: Please enter the IP range (CIDR notation) for the public subnet in the second Availability Zone
Type: String
Default: 10.192.11.0/24
PublicSubnet3CIDR:
Description: Please enter the IP range (CIDR notation) for the public subnet in the second Availability Zone
Type: String
Default: 10.192.12.0/24
PrivateSubnet1CIDR:
Description: Please enter the IP range (CIDR notation) for the private subnet in the first Availability Zone
Type: String
Default: 10.192.20.0/24
PrivateSubnet2CIDR:
Description: Please enter the IP range (CIDR notation) for the private subnet in the second Availability Zone
Type: String
Default: 10.192.21.0/24
PrivateSubnet3CIDR:
Description: Please enter the IP range (CIDR notation) for the private subnet in the second Availability Zone
Type: String
Default: 10.192.22.0/24
DBClass:
Description: Database instance class
Type: String
Default: db.m6g.xlarge
AllowedValues:
- db.m5.xlarge
- db.m6g.xlarge
- db.r5.xlarge
- db.r6g.xlarge
- db.t3.xalrge
ConstraintDescription: must select a valid database instance type.
DBUser:
Description: The CVAT database admin account username
Default: postgres
Type: String
MinLength: '1'
MaxLength: '16'
AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
ConstraintDescription: must begin with a letter and contain only alphanumeric characters.
DBPassword:
Description: The CVAT database admin account password
Default: cvat123456
Type: String
MinLength: '8'
MaxLength: '41'
AllowedPattern: '[a-zA-Z0-9]*'
ConstraintDescription: must contain only alphanumeric characters.
MultiAZDatabase:
Default: 'false'
Description: Create a Multi-AZ MySQL Amazon RDS database instance
Type: String
AllowedValues:
- 'true'
- 'false'
ConstraintDescription: must be either true or false.
DBAllocatedStorage:
Default: '50'
Description: The size of the database (Gb)
Type: Number
MinValue: '5'
MaxValue: '1024'
ConstraintDescription: must be between 5 and 1024Gb.
CVATUser:
Description: The CVAT admin account username
Default: admin
Type: String
MinLength: '1'
MaxLength: '16'
AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
ConstraintDescription: must begin with a letter and contain only alphanumeric characters.
CVATPassword:
Description: The CVAT admin account password
Default: cvat123456
Type: String
MinLength: '8'
MaxLength: '41'
AllowedPattern: '[a-zA-Z0-9]*'
ConstraintDescription: must contain only alphanumeric characters.
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref VpcCIDR
EnableDnsSupport: true
EnableDnsHostnames: true
Tags:
- Key: Name
Value: !Sub ${AWS::StackName} VPC
InternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: !Ref AWS::StackName
InternetGatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId: !Ref InternetGateway
VpcId: !Ref VPC
PublicSubnet1:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select [ 0, !GetAZs '' ]
CidrBlock: !Ref PublicSubnet1CIDR
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: !Sub ${AWS::StackName} Public Subnet (AZ1)
PublicSubnet2:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select [ 1, !GetAZs '' ]
CidrBlock: !Ref PublicSubnet2CIDR
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: !Sub ${AWS::StackName} Public Subnet (AZ2)
PublicSubnet3:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select [ 2, !GetAZs '' ]
CidrBlock: !Ref PublicSubnet3CIDR
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: !Sub ${AWS::StackName} Public Subnet (AZ3)
PrivateSubnet1:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select [ 0, !GetAZs '' ]
CidrBlock: !Ref PrivateSubnet1CIDR
MapPublicIpOnLaunch: false
Tags:
- Key: Name
Value: !Sub ${AWS::StackName} Private Subnet (AZ1)
PrivateSubnet2:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select [ 1, !GetAZs '' ]
CidrBlock: !Ref PrivateSubnet2CIDR
MapPublicIpOnLaunch: false
Tags:
- Key: Name
Value: !Sub ${AWS::StackName} Private Subnet (AZ2)
PrivateSubnet3:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select [ 2, !GetAZs '' ]
CidrBlock: !Ref PrivateSubnet3CIDR
MapPublicIpOnLaunch: false
Tags:
- Key: Name
Value: !Sub ${AWS::StackName} Private Subnet (AZ3)
NatGateway1EIP:
Type: AWS::EC2::EIP
DependsOn: InternetGatewayAttachment
Properties:
Domain: vpc
Tags:
- Key: Name
Value: !Sub ${AWS::StackName} NGW(AZ1)
NatGateway2EIP:
Type: AWS::EC2::EIP
DependsOn: InternetGatewayAttachment
Properties:
Domain: vpc
Tags:
- Key: Name
Value: !Sub ${AWS::StackName} NGW(AZ2)
NatGateway3EIP:
Type: AWS::EC2::EIP
DependsOn: InternetGatewayAttachment
Properties:
Domain: vpc
Tags:
- Key: Name
Value: !Sub ${AWS::StackName} NGW(AZ3)
NatGateway1:
Type: AWS::EC2::NatGateway
Properties:
AllocationId: !GetAtt NatGateway1EIP.AllocationId
SubnetId: !Ref PublicSubnet1
NatGateway2:
Type: AWS::EC2::NatGateway
Properties:
AllocationId: !GetAtt NatGateway2EIP.AllocationId
SubnetId: !Ref PublicSubnet2
NatGateway3:
Type: AWS::EC2::NatGateway
Properties:
AllocationId: !GetAtt NatGateway3EIP.AllocationId
SubnetId: !Ref PublicSubnet3
PublicRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub ${AWS::StackName} Public Routes
DefaultPublicRoute:
Type: AWS::EC2::Route
DependsOn: InternetGatewayAttachment
Properties:
RouteTableId: !Ref PublicRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
PublicSubnet1RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PublicRouteTable
SubnetId: !Ref PublicSubnet1
PublicSubnet2RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PublicRouteTable
SubnetId: !Ref PublicSubnet2
PublicSubnet3RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PublicRouteTable
SubnetId: !Ref PublicSubnet3
PrivateRouteTable1:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub ${AWS::StackName} Private Routes (AZ1)
DefaultPrivateRoute1:
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref PrivateRouteTable1
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref NatGateway1
PrivateSubnet1RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PrivateRouteTable1
SubnetId: !Ref PrivateSubnet1
PrivateRouteTable2:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub ${AWS::StackName} Private Routes (AZ2)
DefaultPrivateRoute2:
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref PrivateRouteTable2
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref NatGateway2
PrivateSubnet2RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PrivateRouteTable2
SubnetId: !Ref PrivateSubnet2
PrivateRouteTable3:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub ${AWS::StackName} Private Routes (AZ3)
DefaultPrivateRoute3:
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref PrivateRouteTable3
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref NatGateway3
PrivateSubnet3RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PrivateRouteTable3
SubnetId: !Ref PrivateSubnet3
ALBServerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: "CVAT ALB SG"
GroupDescription: "Security group for CVAT ALB"
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '80'
ToPort: '80'
CidrIp: '0.0.0.0/0'
- IpProtocol: tcp
FromPort: '443'
ToPort: '443'
CidrIp: '0.0.0.0/0'
VpcId: !Ref VPC
AppServerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: "CVAT Server SG"
GroupDescription: "Security group for CVAT Server"
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '8080'
ToPort: '8080'
SourceSecurityGroupId: !Ref ALBServerSecurityGroup
VpcId: !Ref VPC
UIServerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: "CVAT UI SG"
GroupDescription: "Security group for CVAT UI"
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '80'
ToPort: '80'
SourceSecurityGroupId: !Ref ALBServerSecurityGroup
VpcId: !Ref VPC
ServerlessSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: "CVAT Serverless SG"
GroupDescription: "Security group for CVAT Serverless"
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '8070'
ToPort: '8070'
SourceSecurityGroupId: !Ref AppServerSecurityGroup
VpcId: !Ref VPC
SagemakerEndpointSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: "CVAT SageMaker Endpoint SG"
GroupDescription: "Security group for SageMaker Endpoint"
VpcId: !Ref VPC
EfsSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: "CVAT EFS SG"
GroupDescription: "EFS Security Group"
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '2049'
ToPort: '2049'
SourceSecurityGroupId: !Ref AppServerSecurityGroup
VpcId: !Ref VPC
ElasticacheSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: "CVAT Redis SG"
GroupDescription: "Elasticache Security Group"
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '6379'
ToPort: '6379'
SourceSecurityGroupId: !Ref AppServerSecurityGroup
VpcId: !Ref VPC
DBSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: "CVAT Postgresql DB SG"
GroupDescription: "CVAT Postgresql DB SG"
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '5432'
ToPort: '5432'
SourceSecurityGroupId: !Ref AppServerSecurityGroup
VpcId: !Ref VPC
ElasticacheSubnetGroup:
Type: AWS::ElastiCache::SubnetGroup
Properties:
CacheSubnetGroupName: !Sub ${AWS::StackName}-CacheSubnetGroup
Description: "Redis Cache Subnet Group"
SubnetIds:
- !Ref PrivateSubnet1
- !Ref PrivateSubnet2
- !Ref PrivateSubnet3
ElasticacheCluster:
Type: AWS::ElastiCache::CacheCluster
Properties:
Engine: redis
CacheNodeType: cache.r5.large
NumCacheNodes: '1'
CacheSubnetGroupName: !Ref ElasticacheSubnetGroup
VpcSecurityGroupIds:
- !Ref ElasticacheSecurityGroup
DBSubnetGroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupName: !Sub ${AWS::StackName}-DBSubnetGroup
DBSubnetGroupDescription: "CVAT Postgresql DB Subnet Group"
SubnetIds:
- !Ref PrivateSubnet1
- !Ref PrivateSubnet2
- !Ref PrivateSubnet3
DBInstance:
Type: AWS::RDS::DBInstance
Properties:
DBName: cvat
Engine: postgres
MultiAZ: !Ref MultiAZDatabase
MasterUsername: !Ref DBUser
MasterUserPassword: !Ref DBPassword
DBInstanceClass: !Ref DBClass
AllocatedStorage: !Ref DBAllocatedStorage
EngineVersion: '12.7'
DBSubnetGroupName: !Ref DBSubnetGroup
DBInstanceIdentifier: cvat-db
VPCSecurityGroups:
- !Ref DBSecurityGroup
EcsTaskRole:
Type: AWS::IAM::Role
Properties:
RoleName: CVATEcsTaskRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy
Policies:
- PolicyName: SageMakerEnpointInvoke
PolicyDocument:
Version: 2012-10-17
Statement:
- Sid: SageMakerEnpointInvokeSid
Effect: Allow
Action: "sagemaker:InvokeEndpoint"
Resource: "*"
AssumeRolePolicyDocument:
Version: '2008-10-17'
Statement:
- Sid: ''
Effect: Allow
Principal:
Service: ecs-tasks.amazonaws.com
Action: sts:AssumeRole
LogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: /ecs/cvat
CVATEfs:
Type: AWS::EFS::FileSystem
Properties:
FileSystemTags:
- Key: Name
Value: CVAT_EFS
Encrypted: true
EFSMountTarget1:
Type: AWS::EFS::MountTarget
Properties:
FileSystemId: !Ref CVATEfs
SubnetId: !Ref PrivateSubnet1
SecurityGroups:
- !Ref EfsSecurityGroup
EFSMountTarget2:
Type: AWS::EFS::MountTarget
Properties:
FileSystemId: !Ref CVATEfs
SubnetId: !Ref PrivateSubnet2
SecurityGroups:
- !Ref EfsSecurityGroup
EFSMountTarget3:
Type: AWS::EFS::MountTarget
Properties:
FileSystemId: !Ref CVATEfs
SubnetId: !Ref PrivateSubnet3
SecurityGroups:
- !Ref EfsSecurityGroup
DataAccessPoint:
Type: 'AWS::EFS::AccessPoint'
Properties:
FileSystemId: !Ref CVATEfs
PosixUser:
Uid: "1000"
Gid: "1000"
RootDirectory:
CreationInfo:
OwnerGid: "1000"
OwnerUid: "1000"
Permissions: "0755"
Path: "/data"
ShareAccessPoint:
Type: 'AWS::EFS::AccessPoint'
Properties:
FileSystemId: !Ref CVATEfs
PosixUser:
Uid: "1000"
Gid: "1000"
RootDirectory:
CreationInfo:
OwnerGid: "1000"
OwnerUid: "1000"
Permissions: "0755"
Path: "/share"
CmdTaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
ExecutionRoleArn: !GetAtt EcsTaskRole.Arn
ContainerDefinitions:
- LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group: !Ref LogGroup
awslogs-region: !Ref AWS::Region
awslogs-stream-prefix: ecs
EntryPoint:
- sh
- "-c"
PortMappings:
- HostPort: 8080
Protocol: tcp
ContainerPort: 8080
Command:
- >
/opt/venv/bin/python manage.py migrate &&
/opt/venv/bin/python manage.py createsuperuser --no-input
Environment:
- Name: ADAPTIVE_AUTO_ANNOTATION
Value: 'false'
- Name: ALLOWED_HOSTS
Value: "*"
- Name: CVAT_POSTGRES_HOST
Value: !GetAtt DBInstance.Endpoint.Address
- Name: CVAT_POSTGRES_PASSWORD
Value: !Ref DBPassword
- Name: CVAT_POSTGRES_USER
Value: !Ref DBUser
- Name: CVAT_REDIS_HOST
Value: !GetAtt ElasticacheCluster.RedisEndpoint.Address
- Name: DJANGO_MODWSGI_EXTRA_ARGS
Value: ''
- Name: DJANGO_SUPERUSER_EMAIL
Value: admin@example.com
- Name: DJANGO_SUPERUSER_PASSWORD
Value: !Ref CVATPassword
- Name: DJANGO_SUPERUSER_USERNAME
Value: !Ref CVATUser
MountPoints:
- ContainerPath: "/home/django/data"
SourceVolume: cvat-data
- ContainerPath: "/home/django/share"
SourceVolume: cvat-share
Image: '975230531453.dkr.ecr.ap-northeast-1.amazonaws.com/dockerhub/openvino/cvat_server'
Name: cvat-server-container
Memory: '2048'
TaskRoleArn: !GetAtt EcsTaskRole.Arn
Family: cvat-cmd-task
RequiresCompatibilities:
- FARGATE
NetworkMode: awsvpc
Cpu: '1024'
Volumes:
- EFSVolumeConfiguration:
FilesystemId: !Ref CVATEfs
AuthorizationConfig:
AccessPointId: !Ref DataAccessPoint
TransitEncryption: ENABLED
RootDirectory: "/"
Name: cvat-data
- EFSVolumeConfiguration:
FilesystemId: !Ref CVATEfs
AuthorizationConfig:
AccessPointId: !Ref ShareAccessPoint
TransitEncryption: ENABLED
RootDirectory: "/"
Name: cvat-share
ServerTaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
ExecutionRoleArn: !GetAtt EcsTaskRole.Arn
ContainerDefinitions:
- LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group: !Ref LogGroup
awslogs-region: !Ref AWS::Region
awslogs-stream-prefix: ecs
PortMappings:
- HostPort: 8080
Protocol: tcp
ContainerPort: 8080
Environment:
- Name: ADAPTIVE_AUTO_ANNOTATION
Value: 'false'
- Name: ALLOWED_HOSTS
Value: "*"
- Name: CVAT_POSTGRES_HOST
Value: !GetAtt DBInstance.Endpoint.Address
- Name: CVAT_POSTGRES_PASSWORD
Value: !Ref DBPassword
- Name: CVAT_POSTGRES_USER
Value: !Ref DBUser
- Name: CVAT_REDIS_HOST
Value: !GetAtt ElasticacheCluster.RedisEndpoint.Address
- Name: DJANGO_MODWSGI_EXTRA_ARGS
Value: ''
- Name: CVAT_NUCLIO_HOST
Value: serverless.cvat.local
- Name: CVAT_SERVERLESS
Value: 1
MountPoints:
- ContainerPath: "/home/django/data"
SourceVolume: cvat-data
- ContainerPath: "/home/django/share"
SourceVolume: cvat-share
Image: '975230531453.dkr.ecr.ap-northeast-1.amazonaws.com/dockerhub/openvino/cvat_server'
Name: cvat-server-container
Memory: '4096'
TaskRoleArn: !GetAtt EcsTaskRole.Arn
Family: cvat-server-task
RequiresCompatibilities:
- FARGATE
NetworkMode: awsvpc
Cpu: '2048'
Volumes:
- EFSVolumeConfiguration:
FilesystemId: !Ref CVATEfs
AuthorizationConfig:
AccessPointId: !Ref DataAccessPoint
TransitEncryption: ENABLED
RootDirectory: "/"
Name: cvat-data
- EFSVolumeConfiguration:
FilesystemId: !Ref CVATEfs
AuthorizationConfig:
AccessPointId: !Ref ShareAccessPoint
TransitEncryption: ENABLED
RootDirectory: "/"
Name: cvat-share
UITaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
ExecutionRoleArn: !GetAtt EcsTaskRole.Arn
ContainerDefinitions:
- LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group: !Ref LogGroup
awslogs-region: !Ref AWS::Region
awslogs-stream-prefix: ecs
PortMappings:
- HostPort: 80
Protocol: tcp
ContainerPort: 80
Image: '975230531453.dkr.ecr.ap-northeast-1.amazonaws.com/dockerhub/openvino/cvat_ui'
Name: cvat-ui-container
Memory: '512'
TaskRoleArn: !GetAtt EcsTaskRole.Arn
Family: cvat-ui-task
RequiresCompatibilities:
- FARGATE
NetworkMode: awsvpc
Cpu: '256'
ServerlessTaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
ExecutionRoleArn: !GetAtt EcsTaskRole.Arn
ContainerDefinitions:
- LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group: !Ref LogGroup
awslogs-region: !Ref AWS::Region
awslogs-stream-prefix: ecs
PortMappings:
- HostPort: 8070
Protocol: tcp
ContainerPort: 8070
Environment:
- Name: SERVERLESS_SAGEMAKER_ENDPOINT
Value: !GetAtt CvatSagemakerEndpoint.EndpointName
- Name: ALLOWED_HOSTS
Value: '*'
Image: '975230531453.dkr.ecr.ap-northeast-1.amazonaws.com/dockerhub/openvino/cvat_serverless'
Name: cvat-serverless-container
Memory: '2048'
TaskRoleArn: !GetAtt EcsTaskRole.Arn
Family: cvat-serverless-task
RequiresCompatibilities:
- FARGATE
NetworkMode: awsvpc
Cpu: '1024'
DatasetTaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
ExecutionRoleArn: !GetAtt EcsTaskRole.Arn
ContainerDefinitions:
- LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group: !Ref LogGroup
awslogs-region: !Ref AWS::Region
awslogs-stream-prefix: ecs
Command:
- s3
- --no-sign-request
- cp
- s3://cvat-aws/dataset/persons.jpg
- /mnt/
MountPoints:
- ContainerPath: /mnt
SourceVolume: cvat-share
Image: amazon/aws-cli
Essential: False
Name: dataset-s3-container1
- LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group: !Ref LogGroup
awslogs-region: !Ref AWS::Region
awslogs-stream-prefix: ecs
Command:
- s3
- --no-sign-request
- cp
- s3://cvat-aws/dataset/handball.tar.gz
- /mnt/
MountPoints:
- ContainerPath: /mnt
SourceVolume: cvat-share
Image: amazon/aws-cli
Essential: False
Name: dataset-s3-container2
- LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group: !Ref LogGroup
awslogs-region: !Ref AWS::Region
awslogs-stream-prefix: ecs
EntryPoint:
- bash
- "-c"
Command:
- >
tar --owner=1000 --group=1000 --numeric-owner -zxvf /mnt/handball.tar.gz -C /mnt/ &&
rm /mnt/handball.tar.gz
DependsOn:
- Condition: SUCCESS
ContainerName: dataset-s3-container1
- Condition: SUCCESS
ContainerName: dataset-s3-container2
MountPoints:
- ContainerPath: /mnt
SourceVolume: cvat-share
Image: ubuntu:20.04
Name: dataset-tar-container
Memory: '2048'
TaskRoleArn: !GetAtt EcsTaskRole.Arn
Family: dataset-cmd-task
RequiresCompatibilities:
- FARGATE
NetworkMode: awsvpc
Cpu: '1024'
Volumes:
- EFSVolumeConfiguration:
FilesystemId: !Ref CVATEfs
AuthorizationConfig:
AccessPointId: !Ref ShareAccessPoint
TransitEncryption: ENABLED
RootDirectory: "/"
Name: cvat-share
LambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Path: /
Policies:
- PolicyName: root
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 'logs:CreateLogGroup'
- 'logs:CreateLogStream'
- 'logs:PutLogEvents'
Resource: '*'
- Effect: Allow
Action:
- ecs:RunTask
- iam:PassRole
Resource: '*'
RunCmdFunction:
Type: AWS::Lambda::Function
Properties:
Code:
ZipFile: |
import boto3
import urllib3
import json
SUCCESS = "SUCCESS"
FAILED = "FAILED"
http = urllib3.PoolManager()
def lambda_handler(event, context):
print(event)
if (event['RequestType'] == 'Create'):
try:
client = boto3.client('ecs')
print("Running task.")
response = client.run_task(
cluster=event['ResourceProperties']['Cluster'],
launchType='FARGATE',
taskDefinition=event['ResourceProperties']['TaskDefinition'], # <-- notice no revision number
count=1,
platformVersion='LATEST',
networkConfiguration={
'awsvpcConfiguration': {
'subnets': event['ResourceProperties']['Subnets'],
'securityGroups': [event['ResourceProperties']['securityGroups']],
'assignPublicIp': 'DISABLED'
}
})
print("Finished invoking task.")
except Exception as e:
send(event, context, FAILED, {'exception': str(e)})
send(event, context, SUCCESS, dict())
def send(event, context, responseStatus, responseData, physicalResourceId=None, noEcho=False, reason=None):
responseUrl = event['ResponseURL']
print(responseUrl)
responseBody = {
'Status' : responseStatus,
'Reason' : reason or "See the details in CloudWatch Log Stream: {}".format(context.log_stream_name),
'PhysicalResourceId' : physicalResourceId or context.log_stream_name,
'StackId' : event['StackId'],
'RequestId' : event['RequestId'],
'LogicalResourceId' : event['LogicalResourceId'],
'NoEcho' : noEcho,
'Data' : responseData
}
json_responseBody = json.dumps(responseBody)
print("Response body:")
print(json_responseBody)
headers = {
'content-type' : '',
'content-length' : str(len(json_responseBody))
}
try:
response = http.request('PUT', responseUrl, headers=headers, body=json_responseBody)
print("Status code:", response.status)
except Exception as e:
print("send failed executing:", e)
Handler: index.lambda_handler
Role: !GetAtt LambdaExecutionRole.Arn
Runtime: python3.6
Timeout: '300'
CvatCmdCustom:
Type: Custom::CvatCmd
DependsOn: CmdTaskDefinition
Properties:
ServiceToken: !GetAtt RunCmdFunction.Arn
Region: !Ref AWS::Region
Cluster: !Ref ECSCluster
TaskDefinition: cvat-cmd-task
Subnets:
- !Ref PrivateSubnet1
- !Ref PrivateSubnet2
- !Ref PrivateSubnet3
securityGroups: !Ref AppServerSecurityGroup
DatasetCmdCustom:
Type: Custom::DatasetCmd
DependsOn: DatasetTaskDefinition
Properties:
ServiceToken: !GetAtt RunCmdFunction.Arn
Region: !Ref AWS::Region
Cluster: !Ref ECSCluster
TaskDefinition: dataset-cmd-task
Subnets:
- !Ref PrivateSubnet1
- !Ref PrivateSubnet2
- !Ref PrivateSubnet3
securityGroups: !Ref AppServerSecurityGroup
CvatApplicationLoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Name: cvat-alb
Scheme: internet-facing
SecurityGroups:
- !Ref ALBServerSecurityGroup
Subnets:
- !Ref PublicSubnet1
- !Ref PublicSubnet2
- !Ref PublicSubnet3
Type: application
CvatUITargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
Name: cvat-ui-target
Protocol: HTTP
TargetType: ip
VpcId: !Ref VPC
Port: 80
TargetGroupAttributes:
- Key: deregistration_delay.timeout_seconds
Value: 60
CvatServerTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
Name: cvat-server-target
Protocol: HTTP