-
Notifications
You must be signed in to change notification settings - Fork 33
/
03-application-ohdsi.yaml
1732 lines (1627 loc) · 121 KB
/
03-application-ohdsi.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
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License.
# A copy of the License is located at
# http://aws.amazon.com/apache2.0/
# or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific language governing permissions and limitations under the License.
AWSTemplateFormatVersion: '2010-09-09'
Description: This CloudFormation Template deploys a complete OHDSI environment. It
depends on the OHDSI-VPC CloudFormation Template.
Parameters:
WebAsgMax:
AllowedPattern: ^((?!0$)[1-2]?[0-9]|30)$
ConstraintDescription: Must be a number between 1 and 30.
Default: 1
Description: Specifies the maximum number of EC2 instances in the Web Autoscaling Group.
Type: String
WebAsgMin:
AllowedPattern: ^([0-0]?[0-9]|10)$
ConstraintDescription: Must be a number between 0 and 10.
Default: 1
Description: Specifies the minimum number of EC2 instances in the Web Autoscaling Group.
Type: String
WebInstanceType:
AllowedValues:
- t2.micro
- t2.small
- t2.medium
- t2.large
- t2.xlarge
- t2.2xlarge
- t3.micro
- t3.small
- t3.medium
- t3.large
- t3.xlarge
- t3.2xlarge
- m4.large
- m4.xlarge
- m4.2xlarge
- m5.large
- m5.xlarge
- m5.2xlarge
- c4.large
- c4.xlarge
- c4.2xlarge
- c5.large
- c5.xlarge
- c5.2xlarge
- r4.large
- r4.xlarge
- r5.large
- r5.xlarge
ConstraintDescription: Must be a valid Amazon EC2 instance type.
Default: t2.micro
Description: The Amazon EC2 instance type for your web instances.
Type: String
SslCertificate:
Type: String
Description: "AWS ARN to ACM generated SSL certificate."
EBEndpoint:
Description: "The unique name to use for your Elastic Beanstalk URL (will be rendered http://(EBEndpoint).(region).elasticbeanstalk.com)"
Type: String
UseRoute53Boolean:
AllowedValues:
- true
- false
Default: true
Description: Specifies whether a record set should be created in Route 53 for your OHDSI domain name. If not, you will recieve a default Elastic Beanstalk DNS name (e.g. ohdsi.us-east-1.elasticbeanstalk.com).
Type: String
UseACMBoolean:
AllowedValues:
- true
- false
Default: true
Description: Specifies whether an SSL certificate should be generated for your domain name using AWS Certificate Manager (ACM). If one is not generated, HTTP will be used and an SSL certificate can be applied after deployment.
Type: String
HostedZoneName:
Type: String
Description: "The hosted zone that will be used by your application. If using the Elastic Beanstalk provided hosted zone in us-east-1, just accept the default value."
Default: us-east-1.elasticbeanstalk.com
DomainName:
AllowedPattern: ^$|(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$
Description: '[ Optional, only if using Route53 ] The sub-domain name of the OHDSI site. This sub-domain will be prepended your specified Hosted Zone (e.g. ohdsi in ohdsi.example.edu).'
Type: String
DatabaseMasterPassword:
Description: Must be letters (upper or lower), numbers, spaces, and these special characters `~#$%^&*()_+,-
Type: String
NoEcho: true
AllowedPattern: ^([a-zA-Z0-9`~#$%^&*()_+,\\-])*$
ConstraintDescription: The Amazon RDS master password. Letters, numbers, spaces, and these special characters `~#$%^&*()_+,-
Sources:
Description: Comma-delimited list of OMOP CDM schema sources to load into the Redshift datawarehouse
Type: String
AllowedPattern: ^([a-zA-Z0-9,])*$
Default: CMSDESynPUF1k,CMSDESynPUF23m
SourcesBucket:
Description: S3 Bucket that contains DDL SQL files name after each 'Source'.sql that will be executed to load data into the OMOP CDM schema sources.
Type: String
AllowedPattern: ^([a-zA-Z0-9`~#$%^&*()_+,\\-])*$
Default: ohdsi-sample-data
OMOPv:
Description: The OHDSI CommonDataModel GitHub branch you want deployed (this specifies the version)
Type: String
Default: 'v5.3.1'
Atlasv:
Description: The OHDSI Atlas GitHub branch you want deployed (this specifies the version)
Type: String
Default: 'v2.7.1'
WebAPIv:
Description: OHDSI WebAPI GitHub branch you want deployed (this specifies the version)
Type: String
Default: 'v2.7.1'
Achillesv:
Description: OHDSI Achilles GitHub branch you want deployed (this specifies the version)
Type: String
Default: 'v1.5.0'
OhdsiRToolsv:
Description: OhdsiRTools GitHub branch you want deployed (this specifies the version)
Type: String
Default: 'v1.5.3'
SqlRenderv:
Description: OHDSI SqlRender GitHub branch you want deployed (this specifies the version)
Type: String
Default: 'v1.4.10'
DatabaseConnectorv:
Description: OHDSI DatabaseConnector GitHub branch you want deployed (this specifies the version)
Type: String
Default: 'v2.1.0'
DatabaseConnectorJarsv:
Description: OHDSI DatabaseConnector GitHub branch you want deployed (this specifies the version)
Type: String
Default: 'v1.0.0'
EC2KeyName:
Description: The EC2 Key Pair to use for the Atlas/WebAPI EC2 Instances.
Type: AWS::EC2::KeyPair::KeyName
PrivateDeployment:
Type: String
Description: "Is this going to be a private network deployment of OHDSI?"
AllowedValues:
- "true"
- "false"
Default: false
AtlasSecurity:
Type: String
Description: "Use the RStudio usernames and passwords to authenticate access to Atlas?"
AllowedValues:
- true
- false
Default: false
ExampleStudies:
Type: String
Description: "Include example studies in Atlas?"
AllowedValues:
- true
- false
Default: true
UserList:
Description: Provide a comma separated list of usernames and passwords (user1,pass1,user2,pass2) to create on the R-Studio Server.
Type: 'String'
NoEcho: true
VPCId:
Type: AWS::EC2::VPC::Id
SubnetPublicA:
Type: AWS::EC2::Subnet::Id
SubnetPublicB:
Type: AWS::EC2::Subnet::Id
SubnetAppA:
Type: AWS::EC2::Subnet::Id
SubnetAppB:
Type: AWS::EC2::Subnet::Id
SGPublic:
Type: AWS::EC2::SecurityGroup::Id
SGApp:
Type: AWS::EC2::SecurityGroup::Id
EBServiceRole:
Type: String
EBInstanceProfile:
Type: String
TempEC2InstanceProfile:
Type: String
RStudioTargetGroupArn:
Type: String
JupyterTargetGroupArn:
Type: String
RDSEndpoint:
Type: String
RedshiftEndpoint:
Type: String
EBBucket:
Type: String
Description: 'S3 Bucket used to store the application package for Elastic Beanstalk.'
RSRoleArn:
Type: String
#Mapping to find the Amazon Linux AMI in each region. This AMI is used for the temporary EC2 server.
Mappings:
RegionMap:
us-east-1:
AMI: ami-0d5eff06f840b45e9
us-east-2:
AMI: ami-0443305dabd4be2bc
us-west-1:
AMI: ami-04468e03c37242e1e
us-west-2:
AMI: ami-0cf6f5c8a62fa5da6
ca-central-1:
AMI: ami-0101734ab73bd9e15
eu-west-1:
AMI: ami-063d4ab14480ac177
eu-west-2:
AMI: ami-06dc09bb8854cbde3
eu-west-3:
AMI: ami-0b3e57ee3b63dd76b
eu-central-1:
AMI: ami-043097594a7df80ec
sa-east-1:
AMI: ami-05373777d08895384
ap-south-1:
AMI: ami-010aff33ed5991201
ap-southeast-1:
AMI: ami-02f26adf094f51167
ap-southeast-2:
AMI: ami-0186908e2fdeea8f3
ap-northeast-1:
AMI: ami-0ca38c7440de1749a
ap-northeast-2:
AMI: ami-0f2c95e9fe3f8f80e
ap-northeast-3:
AMI: ami-056314235f4f5d523
tomcatconfig:
t2.micro:
Xmx: 512m
t2.small:
Xmx: 1024m
t2.medium:
Xmx: 2048m
t2.large:
Xmx: 4096m
t2.xlarge:
Xmx: 8192m
t2.2xlarge:
Xmx: 16384m
t3.micro:
Xmx: 512m
t3.small:
Xmx: 1024m
t3.medium:
Xmx: 2048m
t3.large:
Xmx: 4096m
t3.xlarge:
Xmx: 8192m
t3.2xlarge:
Xmx: 16384m
m4.large:
Xmx: 4096m
m4.xlarge:
Xmx: 8192m
m4.2xlarge:
Xmx: 16384m
m5.large:
Xmx: 4096m
m5.xlarge:
Xmx: 8192m
m5.2xlarge:
Xmx: 16384m
c4.large:
Xmx: 2048m
c4.xlarge:
Xmx: 4096m
c4.2xlarge:
Xmx: 8192m
c5.large:
Xmx: 2048m
c5.xlarge:
Xmx: 4096m
c5.2xlarge:
Xmx: 8192m
r4.large:
Xmx: 8192m
r4.xlarge:
Xmx: 16384m
r5.large:
Xmx: 8192m
r5.xlarge:
Xmx: 16384m
Conditions:
DeployRoute53:
!Equals [ true, !Ref UseRoute53Boolean ]
PrivateDeploy:
!Equals [ true, !Ref PrivateDeployment ]
DeployACM: !And
- !Equals [ true, !Ref UseACMBoolean ]
- !Condition DeployRoute53
NotDeployACM: !Or
- !Equals [ false, !Ref UseACMBoolean ]
- !Equals [ false, !Ref UseRoute53Boolean ]
Resources:
# Defines the Elastic Beanstalk environment that deploys the load balancer and Atlas/WebAPI Tomcat servers in an auto-scaling group.
OHDSIApp:
Type: 'AWS::ElasticBeanstalk::Application'
DependsOn: EC2WaitCondition
Properties:
Description: OHDSI Atlas and WebAPI
OHDSIAppVersion:
Type: 'AWS::ElasticBeanstalk::ApplicationVersion'
DependsOn: EC2WaitCondition
Properties:
ApplicationName: !Ref OHDSIApp
Description: Version 1.0
SourceBundle:
S3Bucket: !Ref EBBucket
S3Key: ohdsi-webapi-atlas.zip
OHDSIEnvironmentACM:
Type: 'AWS::ElasticBeanstalk::Environment'
Condition: DeployACM
DependsOn: EC2WaitCondition
Properties:
ApplicationName: !Ref OHDSIApp
Description: Elastic Beanstalk deployment of Atlas / WebAPI
SolutionStackName: !Select [1, !Split ['"', !Select [0, !Split ['}', !Select [1, !Split [':', !GetAtt 'EC2WaitCondition.Data']]]]]]
VersionLabel: !Ref OHDSIAppVersion
EnvironmentName: !Ref EBEndpoint
CNAMEPrefix: !Ref EBEndpoint
Tier:
Name: WebServer
Type: Standard
Version: ' '
OptionSettings:
- Namespace: 'aws:autoscaling:launchconfiguration'
OptionName: IamInstanceProfile
Value: !Ref EBInstanceProfile
- Namespace: 'aws:elasticbeanstalk:environment'
OptionName: ServiceRole
Value: !Ref EBServiceRole
- Namespace: aws:elasticbeanstalk:environment
OptionName: EnvironmentType
Value: LoadBalanced
- Namespace: aws:autoscaling:asg
OptionName: MinSize
Value: !Ref WebAsgMin
- Namespace: aws:autoscaling:asg
OptionName: MaxSize
Value: !Ref WebAsgMax
- Namespace: aws:autoscaling:launchconfiguration
OptionName: EC2KeyName
Value: !Ref 'EC2KeyName'
- Namespace: aws:autoscaling:launchconfiguration
OptionName: InstanceType
Value: !Ref WebInstanceType
- Namespace: aws:autoscaling:launchconfiguration
OptionName: SecurityGroups
Value: !Ref SGApp
- Namespace: aws:autoscaling:launchconfiguration
OptionName: SSHSourceRestriction
Value: 'tcp, 22, 22, 127.0.0.1/32'
- Namespace: aws:autoscaling:trigger
OptionName: MeasureName
Value: CPUUtilization
- Namespace: aws:autoscaling:trigger
OptionName: Unit
Value: Percent
- Namespace: aws:autoscaling:trigger
OptionName: UpperThreshold
Value: '80'
- Namespace: aws:autoscaling:trigger
OptionName: LowerThreshold
Value: '20'
- Namespace: aws:autoscaling:updatepolicy:rollingupdate
OptionName: MaxBatchSize
Value: '1'
- Namespace: aws:autoscaling:updatepolicy:rollingupdate
OptionName: MinInstancesInService
Value: '0'
- Namespace: aws:autoscaling:updatepolicy:rollingupdate
OptionName: RollingUpdateEnabled
Value: 'true'
- Namespace: aws:autoscaling:updatepolicy:rollingupdate
OptionName: RollingUpdateType
Value: Health
- Namespace: aws:ec2:vpc
OptionName: AssociatePublicIpAddress
Value: 'false'
- Namespace: aws:ec2:vpc
OptionName: ELBScheme
Value: !If [ PrivateDeploy, 'internal', 'public' ]
- Namespace: aws:ec2:vpc
OptionName: ELBSubnets
Value: !Join
- ','
- - !Ref SubnetPublicA
- !Ref SubnetPublicB
- Namespace: aws:ec2:vpc
OptionName: Subnets
Value: !Join
- ','
- - !Ref SubnetAppA
- !Ref SubnetAppB
- Namespace: aws:ec2:vpc
OptionName: VPCId
Value: !Ref VPCId
- Namespace: aws:elasticbeanstalk:command
OptionName: DeploymentPolicy
Value: Rolling
- Namespace: aws:elasticbeanstalk:environment
OptionName: LoadBalancerType
Value: application
- Namespace: aws:elasticbeanstalk:healthreporting:system
OptionName: SystemType
Value: enhanced
- Namespace: aws:elasticbeanstalk:application
OptionName: 'Application Healthcheck URL'
Value: '/WebAPI/info'
- Namespace: aws:elbv2:loadbalancer
OptionName: IdleTimeout
Value: 240
- Namespace: aws:elbv2:loadbalancer
OptionName: SecurityGroups
Value: !Ref SGPublic
- Namespace: aws:elbv2:loadbalancer
OptionName: ManagedSecurityGroup
Value: !Ref SGPublic
- Namespace: aws:elbv2:listener:default
OptionName: ListenerEnabled
Value: false
- Namespace: aws:elbv2:listener:443
OptionName: DefaultProcess
Value: https
- Namespace: aws:elbv2:listener:443
OptionName: Protocol
Value: HTTPS
- Namespace: aws:elbv2:listener:443
OptionName: SSLCertificateArns
Value: !Ref SslCertificate
- Namespace: aws:elasticbeanstalk:environment:process:https
OptionName: Port
Value: 443
- Namespace: aws:elasticbeanstalk:environment:process:https
OptionName: Protocol
Value: HTTPS
- Namespace: aws:elasticbeanstalk:environment:process:https
OptionName: StickinessEnabled
Value: true
- Namespace: aws:elasticbeanstalk:environment:process:https
OptionName: HealthCheckPath
Value: '/WebAPI/info'
- Namespace: aws:elasticbeanstalk:environment:process:default
OptionName: HealthCheckPath
Value: '/WebAPI/info'
- Namespace: aws:elasticbeanstalk:container:tomcat:jvmoptions
OptionName: Xmx
Value: !FindInMap [tomcatconfig, !Ref WebInstanceType, Xmx]
OHDSIEnvironmentNoACM:
Type: 'AWS::ElasticBeanstalk::Environment'
Condition: NotDeployACM
DependsOn: EC2WaitCondition
Properties:
ApplicationName: !Ref OHDSIApp
Description: OHDSI Atlas and WebAPI
SolutionStackName: !Select [1, !Split ['"', !Select [0, !Split ['}', !Select [1, !Split [':', !GetAtt 'EC2WaitCondition.Data']]]]]]
VersionLabel: !Ref OHDSIAppVersion
EnvironmentName: !Ref EBEndpoint
CNAMEPrefix: !Ref EBEndpoint
Tier:
Name: WebServer
Type: Standard
Version: ' '
OptionSettings:
- Namespace: 'aws:autoscaling:launchconfiguration'
OptionName: IamInstanceProfile
Value: !Ref EBInstanceProfile
- Namespace: 'aws:elasticbeanstalk:environment'
OptionName: ServiceRole
Value: !Ref EBServiceRole
- Namespace: aws:elasticbeanstalk:environment
OptionName: EnvironmentType
Value: LoadBalanced
- Namespace: aws:autoscaling:asg
OptionName: MinSize
Value: !Ref WebAsgMin
- Namespace: aws:autoscaling:asg
OptionName: MaxSize
Value: !Ref WebAsgMax
- Namespace: aws:autoscaling:launchconfiguration
OptionName: EC2KeyName
Value: !Ref 'EC2KeyName'
- Namespace: aws:autoscaling:launchconfiguration
OptionName: InstanceType
Value: !Ref WebInstanceType
- Namespace: aws:autoscaling:launchconfiguration
OptionName: SecurityGroups
Value: !Ref SGApp
- Namespace: aws:autoscaling:launchconfiguration
OptionName: SSHSourceRestriction
Value: 'tcp, 22, 22, 127.0.0.1/32'
- Namespace: aws:autoscaling:trigger
OptionName: MeasureName
Value: CPUUtilization
- Namespace: aws:autoscaling:trigger
OptionName: Unit
Value: Percent
- Namespace: aws:autoscaling:trigger
OptionName: UpperThreshold
Value: '80'
- Namespace: aws:autoscaling:trigger
OptionName: LowerThreshold
Value: '20'
- Namespace: aws:autoscaling:updatepolicy:rollingupdate
OptionName: MaxBatchSize
Value: '1'
- Namespace: aws:autoscaling:updatepolicy:rollingupdate
OptionName: MinInstancesInService
Value: '0'
- Namespace: aws:autoscaling:updatepolicy:rollingupdate
OptionName: RollingUpdateEnabled
Value: 'true'
- Namespace: aws:autoscaling:updatepolicy:rollingupdate
OptionName: RollingUpdateType
Value: Health
- Namespace: aws:ec2:vpc
OptionName: AssociatePublicIpAddress
Value: 'false'
- Namespace: aws:ec2:vpc
OptionName: ELBScheme
Value: !If [ PrivateDeploy, 'internal', 'public' ]
- Namespace: aws:ec2:vpc
OptionName: ELBSubnets
Value: !Join
- ','
- - !Ref SubnetPublicA
- !Ref SubnetPublicB
- Namespace: aws:ec2:vpc
OptionName: Subnets
Value: !Join
- ','
- - !Ref SubnetAppA
- !Ref SubnetAppB
- Namespace: aws:ec2:vpc
OptionName: VPCId
Value: !Ref VPCId
- Namespace: aws:elasticbeanstalk:command
OptionName: DeploymentPolicy
Value: Rolling
- Namespace: aws:elasticbeanstalk:environment
OptionName: LoadBalancerType
Value: application
- Namespace: aws:elasticbeanstalk:healthreporting:system
OptionName: SystemType
Value: enhanced
- Namespace: aws:elasticbeanstalk:application
OptionName: 'Application Healthcheck URL'
Value: '/WebAPI/info'
- Namespace: aws:elbv2:loadbalancer
OptionName: IdleTimeout
Value: 240
- Namespace: aws:elbv2:loadbalancer
OptionName: SecurityGroups
Value: !Ref SGPublic
- Namespace: aws:elbv2:loadbalancer
OptionName: ManagedSecurityGroup
Value: !Ref SGPublic
- Namespace: aws:elasticbeanstalk:environment:process:default
OptionName: StickinessEnabled
Value: true
- Namespace: aws:elasticbeanstalk:environment:process:https
OptionName: Port
Value: 443
- Namespace: aws:elasticbeanstalk:environment:process:https
OptionName: Protocol
Value: HTTPS
- Namespace: aws:elasticbeanstalk:environment:process:https
OptionName: StickinessEnabled
Value: true
- Namespace: aws:elasticbeanstalk:environment:process:https
OptionName: HealthCheckPath
Value: '/WebAPI/info'
- Namespace: aws:elasticbeanstalk:environment:process:default
OptionName: HealthCheckPath
Value: '/WebAPI/info'
- Namespace: aws:elasticbeanstalk:container:tomcat:jvmoptions
OptionName: Xmx
Value: !FindInMap [tomcatconfig, !Ref WebInstanceType, Xmx]
# This is a temporary EC2 server used to add the necessary Elastic Beanstalk scripts to the Project REDCap source code zip file.
TempEC2Instance:
Type: AWS::EC2::Instance
Metadata:
AWS::CloudFormation::Init:
config:
files:
/etc/awslogs/awslogs.conf:
content: !Sub
- |
[general]
state_file = /var/lib/awslogs/agent-state
[ohdsi-build-log]
file = /var/log/cloud-init-output.log
log_group_name = ohdsi-temporary-ec2-instance-build-log
log_stream_name = ${EB}-build-log
- { EB: !Ref EBEndpoint }
mode: 000664
owner: root
group: root
/etc/awslogs/awscli.conf:
content: !Sub |
[plugins]
cwlogs = cwlogs
[default]
region = ${AWS::Region}
mode: 000664
owner: root
group: root
/etc/yum.repos.d/epel-apache-maven.repo:
content: !Sub |
# Place this file in your /etc/yum.repos.d/ directory
[epel-apache-maven]
name=maven from apache foundation.
baseurl=http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-6/$basearch/
enabled=1
skip_if_unavailable=1
gpgcheck=0
[epel-apache-maven-source]
name=maven from apache foundation. - Source
baseurl=http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-6/SRPMS
enabled=0
skip_if_unavailable=1
gpgcheck=0
mode: 000664
owner: root
group: root
/tmp/config_ohdsi.sh:
content: |
# This script configures the CFN deployed environment for OHDSI WebAPI and Atlas
#
# Requirements:
# $RDS_ENDPOINT must contain the endpoint of the Postgres Aurora RDS environment to be used to store the WebAPI application data
# $EB_ENDPOINT must contain the endpoint of the Elastic Beanstalk Tomcat environment
# $REDSHIFT_ENDPOINT must contain the endpoint of the Redshift Cluster used for OMOP CDM and Vocabulary
# $ACCT_ID must contain the AWS Account ID for the account in which this environment is being deployed
# $BUCKET_NAME must contain the s3 bucket name in which Elastic Beanstalk will look for the ohdsi-webapi-atlas.zip file
# $DATABASE_PASSWORD must contain the password that was used for the master accounts for Redshift and RDS Aurora Postgres
echo "RDS_ENDPOINT=" $RDS_ENDPOINT
echo "EB_ENDPOINT=" $EB_ENDPOINT
echo "REDSHIFT_ENDPOINT=" $REDSHIFT_ENDPOINT
echo "ACCT_ID=" $ACCT_ID
echo "BUCKET_NAME=" $BUCKET_NAME
echo "DATABASE_PASSWORD=" $DATABASE_PASSWORD
echo "OHDSIADMINUSERPWHASH=" $OHDSIADMINUSERPWHASH
echo "OHDSIAPPUSERPWHASH=" $OHDSIAPPUSERPWHASH
export AWS_DEFAULT_REGION=$(echo $EB_ENDPOINT | cut -d . -f2)
aws s3 mb s3://$BUCKET_NAME
curl -sL https://rpm.nodesource.com/setup_14.x | sudo -E bash -
sudo yum install -y nodejs
sudo yum install -y postgresql
sudo amazon-linux-extras install -y postgresql14
export PGPASSWORD=$DATABASE_PASSWORD
sed -i 's!OHDSIADMINUSERPWHASH!'$OHDSIADMINUSERPWHASH'!' postgres_init_master.sql
sed -i 's!OHDSIAPPUSERPWHASH!'$OHDSIAPPUSERPWHASH'!' postgres_init_master.sql
sed -i 's!OHDSISECURITYPWHASH!'$OHDSISECURITYPWHASH'!' postgres_init_master.sql
psql -d postgres --host=$RDS_ENDPOINT --port=5432 -U master -a -f postgres_init_master.sql
psql -d postgres --host=$RDS_ENDPOINT --port=5432 -U ohdsi_admin_user -a -f postgres_init_ohdsi.sql
#Download build tools and compile WebAPI
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash
export NVM_DIR="/root/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
nvm install 11.11.0
sudo wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo --no-check-certificate
sudo sed -i s/\$releasever/6/g /etc/yum.repos.d/epel-apache-maven.repo
sudo yum install -y apache-maven
sudo yum install -y java-1.8.0 java-1.8.0-openjdk-devel
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
sudo /usr/sbin/alternatives --set javac /usr/lib/jvm/java-1.8.0-openjdk.x86_64/bin/javac
#If specified, enable WebAPI security and create users
if [ "$ATLASSECURITY" = "true" ]; then
sudo yum install -y httpd-tools
mkdir ./WebAPI/WebAPIConfig
mv settings_security.xml ./WebAPI/WebAPIConfig/settings.xml
psql -d OHDSI --host=$RDS_ENDPOINT --port=5432 -U ohdsi_security_user -a -f setup_security.sql
count=1
for i in $(echo $ATLASUSERS | sed "s/,/ /g")
do
if [ `expr $count % 2` -eq "1" ]; then
username=$i
let count+=1
continue
else
atlaspw=`htpasswd -bnBC 4 "" $i | tr -d ':\n' | sed 's/$2y/$2a/'`
psql -d OHDSI --host=$RDS_ENDPOINT --port=5432 -U ohdsi_security_user -a -c "insert into authentication.security (email,password) values ('$username', E'$atlaspw');"
let count+=1
fi
done
else
mkdir ./WebAPI/WebAPIConfig
mv settings.xml ./WebAPI/WebAPIConfig
fi
cd WebAPI
#Some versions of WebAPI don't specify https for springsource, and they block http now
if grep -q http://repo.springsource.org pom.xml; then
sed -i 's!http://repo.springsource.org!https://repo.springsource.org!' pom.xml
fi
mvn clean package -Dmaven.test.skip=true -s WebAPIConfig/settings.xml -P webapi-postgresql
cd ..
cp ./WebAPI/target/WebAPI.war .
#Build Atlas "war" file to put at the root URL of the Tomcat server
#If specified, enable Atlas security
if [ "$ATLASSECURITY" = "true" ]; then
mv config-local-secure.js ./Atlas/js/config-local.js
else
mv config-local.js ./Atlas/js/
fi
cd Atlas
npm config set strict-ssl false
npm run build
# The below statements switch the index.html from 'unbundled mode' to 'bundled mode'
commentunbundled=`cat -n index.html | grep data-main=\"js/main\" | cut -f1`
uncommentbundled=`cat -n index.html | grep data-main=\"js/assets/bundle/bundle\" | cut -f1`
sed -i "${commentunbundled}s/.*/ <!-- <script data-main=\"js\/main\" src=\"js\/require.js\"><\/script> -->/" index.html
sed -i "${uncommentbundled}s/.*/ <script data-main=\"js\/assets\/bundle\/bundle\" src=\"js\/require.js\"><\/script>/" index.html
zip -r ../ROOT.war *
cd ..
zip -r ohdsi-webapi-atlas.zip ROOT.war WebAPI.war .ebextensions .platform
aws s3 cp ohdsi-webapi-atlas.zip s3://$BUCKET_NAME
mode: 000777
owner: root
group: root
/tmp/config_db.sh:
content: !Sub
- |
# This script configures the CFN deployed environment for OHDSI WebAPI and Atlas
#
# Requirements:
# $RDS_ENDPOINT must contain the endpoint of the Postgres Aurora RDS environment to be used to store the WebAPI application data
# $EB_ENDPOINT must contain the endpoint of the Elastic Beanstalk Tomcat environment
# $REDSHIFT_ENDPOINT must contain the endpoint of the Redshift Cluster used for OMOP CDM and Vocabulary
# $ACCT_ID must contain the AWS Account ID for the account in which this environment is being deployed
# $BUCKET_NAME must contain the s3 bucket name in which Elastic Beanstalk will look for the ohdsi-webapi-atlas.zip file
# $DATABASE_PASSWORD must contain the password that was used for the master accounts for Redshift and RDS Aurora Postgres
# $RS_ROLE_ARN must contain the role ARN that allows Redshift to read the sample data from S3.
echo "RDS_ENDPOINT=" $RDS_ENDPOINT
echo "EB_ENDPOINT=" $EB_ENDPOINT
echo "REDSHIFT_ENDPOINT=" $REDSHIFT_ENDPOINT
echo "ACCT_ID=" $ACCT_ID
echo "BUCKET_NAME=" $BUCKET_NAME
echo "DATABASE_PASSWORD=" $DATABASE_PASSWORD
echo "RS_ROLE_ARN=" $RS_ROLE_ARN
echo "RSTUDIO_TARGET_GROUP_ARN=" $RSTUDIO_TARGET_GROUP_ARN
echo "SOURCES=" $SOURCES
echo "SOURCESBUCKET= " $SOURCESBUCKET
export AWS_DEFAULT_REGION=$(echo $EB_ENDPOINT | cut -d . -f2)
sudo yum install -y xorg-x11-xauth.x86_64 xorg-x11-server-utils.x86_64 xterm libXt libX11-devel libXt-devel libcurl-devel git compat-gmp4 compat-libffi5 openssl-devel
sudo yum install R R-core R-core-devel R-devel libxml2-devel -y
if [ -f /usr/lib64/R/etc/Makeconf.rpmnew ]; then
sudo cp /usr/lib64/R/etc/Makeconf.rpmnew /usr/lib64/R/etc/Makeconf
fi
if [ -f /usr/lib64/R/etc/ldpaths.rpmnew ]; then
sudo cp /usr/lib64/R/etc/ldpaths.rpmnew /usr/lib64/R/etc/ldpaths
fi
mkdir /mnt/r-stuff
cd /mnt/r-stuff
pushd .
mkdir R-latest
cd R-latest
wget https://cran.r-project.org/src/base/R-4/R-4.1.0.tar.gz
tar -xzf R-4.1.0.tar.gz
#Trying out Python
sudo yum install -y python3 python3-devel python3-pip
sudo yum install -y gcc gcc-c++ gcc-gfortran
sudo yum install -y bzip2-devel readline-devel cairo-devel libpng-devel libjpeg-devel libtiff-devel postgresql-devel
sudo yum install -y pcre2-devel
cd R-4*
./configure --with-readline=yes --enable-R-profiling=no --enable-memory-profiling=no --enable-R-shlib --with-pic --prefix=/usr --with-x --with-libpng --with-jpeglib --with-cairo --enable-R-shlib --with-recommended-packages=yes
make -j 8
sudo make install
sudo su << BASH_SCRIPT
echo 'export PATH=${!PWD}/bin:$PATH' >> /etc/profile
BASH_SCRIPT
popd
sudo sed -i 's/make/make -j 8/g' /usr/lib64/R/etc/Renviron
# set unix environment variables
sudo su << BASH_SCRIPT
echo '
export JAVA_HOME=/etc/alternatives/jre
' >> /etc/profile
BASH_SCRIPT
sudo sh -c "source /etc/profile"
# fix java binding - R and packages have to be compiled with the same java version as hadoop
sudo R CMD javareconf
#Grab R binaries
cd /usr/lib64/R/library
wget https://ohdsi-sample-data.s3.amazonaws.com/ohdsi-rdependencies-symp2022-4.1.0.gzip
unzip -o ohdsi-rdependencies-symp2022-4.1.0.gzip
cd /tmp
#Install R dependencies if any of the specified versions differ
sudo Rscript /tmp/rdependencies.r
#Wait for the WebAPI app to be deployed by Elastic Beanstalk and populate the tables in RDS Postrgres
while [ "`curl -I ${Protocol}${RCDomainName}.${HostedZone} 2>/dev/null | head -n 1 | cut -d$' ' -f2`" != "200" ]
do
sleep 5
done
#Connect R-Studio Instance to the load balancer
export EB_ENVIRONMENT=$(echo $EB_ENDPOINT | cut -d . -f1)
export EB_LB=$(aws elasticbeanstalk describe-environment-resources --environment-name $EB_ENVIRONMENT --query EnvironmentResources.LoadBalancers --output text)
export EB_LB_LISTENER=$(aws elbv2 describe-listeners --load-balancer-arn $EB_LB --query 'Listeners[0].ListenerArn' --output text)
aws elbv2 create-rule --listener-arn $EB_LB_LISTENER --priority 4 --conditions Field=host-header,Values='rstudio.*' --actions Type=forward,TargetGroupArn=$RSTUDIO_TARGET_GROUP_ARN
#Connect Jupyter to the load balancer
export EB_ENVIRONMENT=$(echo $EB_ENDPOINT | cut -d . -f1)
export EB_LB=$(aws elasticbeanstalk describe-environment-resources --environment-name $EB_ENVIRONMENT --query EnvironmentResources.LoadBalancers --output text)
export EB_LB_LISTENER=$(aws elbv2 describe-listeners --load-balancer-arn $EB_LB --query 'Listeners[0].ListenerArn' --output text)
aws elbv2 create-rule --listener-arn $EB_LB_LISTENER --priority 5 --conditions Field=host-header,Values='jupyter.*' --actions Type=forward,TargetGroupArn=$JUPYTER_TARGET_GROUP_ARN
#If using Atlas security, give users permissions in Atlas
export PGPASSWORD=$DATABASE_PASSWORD
if [ "$ATLASSECURITY" = "true" ]; then
count=1
for i in $(echo $ATLASUSERS | sed "s/,/ /g")
do
if [ `expr $count % 2` -eq "1" ]; then
username=$i
let count+=1
continue
else
sleep 5
while [ `curl -w "\\n%{http_code}\\n" -d "login=$username" --data-urlencode "password=$i" -X POST ${Protocol}${RCDomainName}.${HostedZone}/WebAPI/user/login/db 2>/dev/null | tail -n 1` -ne 200 ]
do
sleep 5
done
userid=`psql -d OHDSI --host=$RDS_ENDPOINT --port=5432 -U ohdsi_app_user -t -c "select id from webapi.sec_user where login = '$username';"`
echo $userid >> /tmp/userids.txt
if [ "$count" = "2" ]; then
psql -d OHDSI --host=$RDS_ENDPOINT --port=5432 -U ohdsi_app_user -t -c "insert into webapi.sec_user_role (user_id, role_id) values ($userid,2);"
psql -d OHDSI --host=$RDS_ENDPOINT --port=5432 -U ohdsi_app_user -t -c "insert into webapi.sec_user_role (user_id, role_id) values ($userid,10);"
firstuser=$username
firstpassword="$i"
else
psql -d OHDSI --host=$RDS_ENDPOINT --port=5432 -U ohdsi_app_user -t -c "insert into webapi.sec_user_role (user_id, role_id) values ($userid,10);"
fi
let count+=1
fi
done
fi
cd /tmp
#Deploy the OMOP CDM Schema to Redshift
export REDSHIFTDDL=`ls ./CommonDataModel/Redshift/OMOP*`
#Some of the current Vocabulary data sets from Athena do not have values for these columns
if [ "$CDM_VERSION" = "5.3.1" ]; then
sed -i '47s/.*/ concept_name VARCHAR(255) NULL ,/' "$REDSHIFTDDL"
sed -i '52s/.*/ concept_code VARCHAR(50) NULL ,/' "$REDSHIFTDDL"
sed -i '62s/.*/ vocabulary_reference VARCHAR(255) NULL,/' "$REDSHIFTDDL"
sed -i '63s/.*/ vocabulary_version VARCHAR(255) NULL,/' "$REDSHIFTDDL"
sed -i '226s/.*/ race_source_value VARCHAR(255) NULL,/' "$REDSHIFTDDL"
sed -i '340s/.*/ procedure_source_value VARCHAR(255) NULL ,/' "$REDSHIFTDDL"
sed -i '352s/.*/ drug_exposure_start_date DATE NULL,/' "$REDSHIFTDDL"
sed -i '354s/.*/ drug_exposure_end_date DATE NULL,/' "$REDSHIFTDDL"
sed -i '411s/.*/ condition_source_value VARCHAR(255) NULL,/' "$REDSHIFTDDL"
sed -i '413s/.*/ condition_status_source_value VARCHAR(255) NULL,/' "$REDSHIFTDDL"
sed -i '437s/.*/ measurement_source_value VARCHAR(255) NULL ,/' "$REDSHIFTDDL"
sed -i '440s/.*/ value_source_value VARCHAR(255) NULL/' "$REDSHIFTDDL"
sed -i '494s/.*/ value_as_string VARCHAR(255) NULL ,/' "$REDSHIFTDDL"
sed -i '546s/.*/ place_of_service_source_value VARCHAR(255) NULL/' "$REDSHIFTDDL"
sed -i '676s/.*/ dose_era_start_date DATE NULL,/' "$REDSHIFTDDL"
sed -i '677s/.*/ dose_era_end_date DATE NULL/' "$REDSHIFTDDL"
fi
#Insert Database Credentials into the scripts
sed -i 's!REDSHIFT_ENDPOINT!'$REDSHIFT_ENDPOINT'!' postgres_init_sources.sql
sed -i 's!DATABASE_PASSWORD!'$DATABASE_PASSWORD'!' postgres_init_sources.sql
sed -i 's!REDSHIFT_ENDPOINT!'$REDSHIFT_ENDPOINT'!' /tmp/achilles.r
sed -i 's!DATABASE_PASSWORD!'$DATABASE_PASSWORD'!' /tmp/achilles.r
SOURCECOUNT=0
SOURCEDAEMONCOUNT=0
SOURCEVOCABPRIORITY=0
SOURCERESULTSPRIORITY=0
for i in $(echo $SOURCES | sed "s/,/ /g")
do
export PGPASSWORD=$DATABASE_PASSWORD
cp "$REDSHIFTDDL" "$REDSHIFTDDL-$i"
if [ "$CDM_VERSION" = "5.3.0" ]; then
sed -i 's!@schema_name!'$i'!' "$REDSHIFTDDL-$i"
else
sed -i "1s/^/SET search_path to $i;\n/" "$REDSHIFTDDL-$i"
fi
psql -d mycdm --host=$REDSHIFT_ENDPOINT --port=5439 -U master -a -c "CREATE SCHEMA $i;"
psql -d mycdm --host=$REDSHIFT_ENDPOINT --port=5439 -U master -a -f "$REDSHIFTDDL-$i"
#Deploy the DDL with the appropriate source name and run it
aws s3 cp s3://$SOURCESBUCKET/$i.sql .
sed -i "1s/^/SET search_path to $i;\n/" $i.sql
sed -i 's!RS_ROLE_ARN!'$RS_ROLE_ARN'!' $i.sql
psql -d mycdm --host=$REDSHIFT_ENDPOINT --port=5439 -U master -a -f $i.sql
#Get the Results Schema from WebAPI and apply the Results schema
t="0"
while [ $t -lt 10 ]; do
wget --retry-connrefused --waitretry=2 --read-timeout=20 --timeout=15 -t 10 -q "${Protocol}${RCDomainName}.${HostedZone}/WebAPI/ddl/results?dialect=redshift&schema=${!i}results&vocabSchema=${!i}" -O results_schema.sql --continue
if [ $? = 0 ]; then break; else t=$[$t+1]; fi; # check return value, break if successful (0)
sleep 3s;
done;
psql -d mycdm --host=$REDSHIFT_ENDPOINT --port=5439 -U master -a -c "CREATE SCHEMA ${!i}results;"
psql -d mycdm --host=$REDSHIFT_ENDPOINT --port=5439 -U master -a -f results_schema.sql
rm results_schema.sql
#Create a WebAPI Sources DDL for this Source
cp postgres_init_sources.sql postgres_init_sources-$i.sql
let SOURCECOUNT+=1
if [ "$SOURCECOUNT" = "1" ]; then
SOURCEVOCABPRIORITY=1
SOURCERESULTSPRIORITY=1
sed -i 's!FALSE!'TRUE'!' postgres_init_sources-$i.sql
else
SOURCEVOCABPRIORITY=0
SOURCERESULTSPRIORITY=0
fi
sed -i 's!SOURCECOUNT!'$SOURCECOUNT'!' postgres_init_sources-$i.sql
let SOURCEDAEMONCOUNT+=1
sed -i 's!SOURCEDAEMONCOUNT1!'$SOURCEDAEMONCOUNT'!' postgres_init_sources-$i.sql
let SOURCEDAEMONCOUNT+=1
sed -i 's!SOURCEDAEMONCOUNT2!'$SOURCEDAEMONCOUNT'!' postgres_init_sources-$i.sql
let SOURCEDAEMONCOUNT+=1
sed -i 's!SOURCEDAEMONCOUNT3!'$SOURCEDAEMONCOUNT'!' postgres_init_sources-$i.sql
sed -i 's!SOURCEVOCABPRIORITY!'$SOURCEVOCABPRIORITY'!' postgres_init_sources-$i.sql
sed -i 's!SOURCERESULTSPRIORITY!'$SOURCERESULTSPRIORITY'!' postgres_init_sources-$i.sql
sed -i 's!SOURCENAME_PLACEHOLDER!'$i'!' postgres_init_sources-$i.sql
sed -i 's!SOURCENAME_PLACEHOLDER!'$i'!' postgres_init_sources-$i.sql
sed -i 's!CDM_PLACEHOLDER!'$i'!' postgres_init_sources-$i.sql
sed -i 's!RESULTS_PLACEHOLDER!'${!i}results'!' postgres_init_sources-$i.sql
#Load the sources reference table into the WebAPI Postgres database
export PGPASSWORD=$DATABASE_PASSWORD
psql -d OHDSI --host=$RDS_ENDPOINT --port=5432 -U ohdsi_admin_user -a -f postgres_init_sources-$i.sql
aws elasticbeanstalk restart-app-server --environment-name $(echo $EB_ENDPOINT | cut -d . -f1)
#Inject source information and run Achilles R script to enabled Data Source visualization
cp /tmp/achilles.r /tmp/achilles-$i.r
sed -i 's!SOURCENAME_PLACEHOLDER!'$i'!' /tmp/achilles-$i.r
sed -i 's!CDM_PLACEHOLDER!'$i'!' /tmp/achilles-$i.r
sed -i 's!RESULTS_PLACEHOLDER!'${!i}results'!' /tmp/achilles-$i.r
Rscript /tmp/achilles-$i.r
if [ "$ATLASSECURITY" = "true" ]; then
sourceroleid=`psql -d OHDSI --host=$RDS_ENDPOINT --port=5432 -U ohdsi_app_user -t -c "select id from webapi.sec_role where name LIKE '%$i%';"`
while read userid; do
psql -d OHDSI --host=$RDS_ENDPOINT --port=5432 -U ohdsi_app_user -t -c "insert into webapi.sec_user_role (user_id, role_id) values ($userid,$sourceroleid);"