|
| 1 | +AWSTemplateFormatVersion: 2010-09-09 |
| 2 | +Description: Template for Analytics Dashboard UI deployment on AWS ECS Fargate with NLB |
| 3 | + |
| 4 | +Parameters: |
| 5 | + StaticStackName: |
| 6 | + Type: String |
| 7 | + Default: analytics-dashboard |
| 8 | + Environment: |
| 9 | + Type: String |
| 10 | + Default: staging |
| 11 | + AllowedValues: |
| 12 | + - staging |
| 13 | + - production |
| 14 | + UIPort: |
| 15 | + Type: String |
| 16 | + Default: 8050 |
| 17 | + FrontEndImage: |
| 18 | + Type: String |
| 19 | + ApiBaseUrl: |
| 20 | + Type: String |
| 21 | + VpcId: |
| 22 | + Type: String |
| 23 | + SubnetA: |
| 24 | + Type: String |
| 25 | + SubnetB: |
| 26 | + Type: String |
| 27 | + SubnetC: |
| 28 | + Type: String |
| 29 | + Region: |
| 30 | + Type: String |
| 31 | + Prefix: |
| 32 | + Type: String |
| 33 | + Default: ecs |
| 34 | + ExecutionRole: |
| 35 | + Type: String |
| 36 | + ClusterName: |
| 37 | + Type: String |
| 38 | + CertificateArn: |
| 39 | + Type: String |
| 40 | + ShortName: |
| 41 | + Type: String |
| 42 | + Default: an-db |
| 43 | + |
| 44 | +Resources: |
| 45 | + ALBSecurityGroup: |
| 46 | + Type: AWS::EC2::SecurityGroup |
| 47 | + Properties: |
| 48 | + GroupDescription: Allow inbound HTTP/HTTPS to ALB |
| 49 | + VpcId: !Ref VpcId |
| 50 | + SecurityGroupIngress: |
| 51 | + - IpProtocol: tcp |
| 52 | + FromPort: 80 |
| 53 | + ToPort: 80 |
| 54 | + CidrIp: 0.0.0.0/0 |
| 55 | + - IpProtocol: tcp |
| 56 | + FromPort: 443 |
| 57 | + ToPort: 443 |
| 58 | + CidrIp: 0.0.0.0/0 |
| 59 | + |
| 60 | + ALB: |
| 61 | + Type: AWS::ElasticLoadBalancingV2::LoadBalancer |
| 62 | + Properties: |
| 63 | + Name: !Sub "${ShortName}-${Environment}-fe-alb" |
| 64 | + Type: application |
| 65 | + Scheme: internet-facing |
| 66 | + IpAddressType: ipv4 |
| 67 | + SecurityGroups: |
| 68 | + - !Ref ALBSecurityGroup |
| 69 | + Subnets: |
| 70 | + - Ref: SubnetA |
| 71 | + - Ref: SubnetB |
| 72 | + - Ref: SubnetC |
| 73 | + |
| 74 | + TargetGroup: |
| 75 | + Type: AWS::ElasticLoadBalancingV2::TargetGroup |
| 76 | + Properties: |
| 77 | + Name: !Sub "${ShortName}-${Environment}-fe-tg" |
| 78 | + TargetType: ip |
| 79 | + Protocol: HTTP |
| 80 | + Port: !Ref UIPort |
| 81 | + VpcId: !Ref VpcId |
| 82 | + HealthCheckEnabled: true |
| 83 | + HealthCheckProtocol: HTTP |
| 84 | + HealthCheckPath: /health |
| 85 | + HealthCheckPort: traffic-port |
| 86 | + HealthCheckIntervalSeconds: 30 |
| 87 | + HealthyThresholdCount: 2 |
| 88 | + UnhealthyThresholdCount: 5 |
| 89 | + Matcher: |
| 90 | + HttpCode: 200-399 |
| 91 | + |
| 92 | + ALBListenerHTTP: |
| 93 | + Type: AWS::ElasticLoadBalancingV2::Listener |
| 94 | + DependsOn: |
| 95 | + - ALB |
| 96 | + Properties: |
| 97 | + LoadBalancerArn: !Ref ALB |
| 98 | + Port: 80 |
| 99 | + Protocol: HTTP |
| 100 | + DefaultActions: |
| 101 | + - Type: redirect |
| 102 | + RedirectConfig: |
| 103 | + Protocol: HTTPS |
| 104 | + Port: "443" |
| 105 | + StatusCode: HTTP_301 |
| 106 | + |
| 107 | + ALBListenerHTTPS: |
| 108 | + Type: AWS::ElasticLoadBalancingV2::Listener |
| 109 | + DependsOn: |
| 110 | + - TargetGroup |
| 111 | + - ALB |
| 112 | + Properties: |
| 113 | + LoadBalancerArn: !Ref ALB |
| 114 | + Port: 443 |
| 115 | + Protocol: HTTPS |
| 116 | + Certificates: |
| 117 | + - CertificateArn: !Ref CertificateArn |
| 118 | + DefaultActions: |
| 119 | + - Type: forward |
| 120 | + TargetGroupArn: !Ref TargetGroup |
| 121 | + |
| 122 | + ECSCluster: |
| 123 | + Type: AWS::ECS::Cluster |
| 124 | + Properties: |
| 125 | + ClusterName: !Ref ClusterName |
| 126 | + |
| 127 | + ECSTaskSecurityGroup: |
| 128 | + Type: AWS::EC2::SecurityGroup |
| 129 | + Properties: |
| 130 | + GroupDescription: Allow ALB to reach ECS tasks on Dash port |
| 131 | + VpcId: !Ref VpcId |
| 132 | + SecurityGroupIngress: |
| 133 | + - IpProtocol: tcp |
| 134 | + FromPort: !Ref UIPort |
| 135 | + ToPort: !Ref UIPort |
| 136 | + SourceSecurityGroupId: !Ref ALBSecurityGroup |
| 137 | + SecurityGroupEgress: |
| 138 | + - IpProtocol: -1 |
| 139 | + CidrIp: 0.0.0.0/0 |
| 140 | + |
| 141 | + ECSFrontEndService: |
| 142 | + Type: AWS::ECS::Service |
| 143 | + DependsOn: |
| 144 | + - ECSFrontEndTaskDefinition |
| 145 | + - ALBListenerHTTPS |
| 146 | + - TargetGroup |
| 147 | + Properties: |
| 148 | + Cluster: !Ref ECSCluster |
| 149 | + LaunchType: FARGATE |
| 150 | + DesiredCount: 1 |
| 151 | + HealthCheckGracePeriodSeconds: 120 |
| 152 | + ServiceName: !Sub "${StaticStackName}-${Environment}-fe-service" |
| 153 | + TaskDefinition: !Ref ECSFrontEndTaskDefinition |
| 154 | + NetworkConfiguration: |
| 155 | + AwsvpcConfiguration: |
| 156 | + AssignPublicIp: ENABLED |
| 157 | + SecurityGroups: |
| 158 | + - Fn::ImportValue: !Sub "${StaticStackName}-${Environment}-SGId" |
| 159 | + - !Ref ECSTaskSecurityGroup |
| 160 | + Subnets: |
| 161 | + - !Ref SubnetA |
| 162 | + - !Ref SubnetB |
| 163 | + - !Ref SubnetC |
| 164 | + LoadBalancers: |
| 165 | + - TargetGroupArn: !Ref TargetGroup |
| 166 | + ContainerName: !Sub "${StaticStackName}-${Environment}-fe-container" |
| 167 | + ContainerPort: !Ref UIPort |
| 168 | + |
| 169 | + ECSFrontEndTaskDefinition: |
| 170 | + Type: AWS::ECS::TaskDefinition |
| 171 | + Properties: |
| 172 | + Cpu: 1024 |
| 173 | + Memory: 4096 |
| 174 | + NetworkMode: awsvpc |
| 175 | + ExecutionRoleArn: !Ref ExecutionRole |
| 176 | + RequiresCompatibilities: |
| 177 | + - FARGATE |
| 178 | + RuntimePlatform: |
| 179 | + CpuArchitecture: ARM64 |
| 180 | + OperatingSystemFamily: LINUX |
| 181 | + ContainerDefinitions: |
| 182 | + - Name: !Sub "${StaticStackName}-${Environment}-fe-container" |
| 183 | + Image: !Ref FrontEndImage |
| 184 | + Environment: |
| 185 | + - Name: GA4GH_ANALYTICS_DASHBOARD_API_BASE_URL |
| 186 | + Value: !Ref ApiBaseUrl |
| 187 | + - Name: GA4GH_ANALYTICS_DASHBOARD_UI_PORT |
| 188 | + Value: !Ref UIPort |
| 189 | + LogConfiguration: |
| 190 | + LogDriver: awslogs |
| 191 | + Options: |
| 192 | + awslogs-group: |
| 193 | + Fn::ImportValue: !Sub "${StaticStackName}-${Environment}-frontend-logs" |
| 194 | + awslogs-region: !Ref Region |
| 195 | + awslogs-stream-prefix: !Ref Prefix |
| 196 | + PortMappings: |
| 197 | + - ContainerPort: !Ref UIPort |
| 198 | + |
| 199 | +Outputs: |
| 200 | + ALBDNSName: |
| 201 | + Description: DNS name of the ALB (use this in CNAME record) |
| 202 | + Value: !GetAtt ALB.DNSName |
0 commit comments