|
| 1 | +AWSTemplateFormatVersion: "2010-09-09" |
| 2 | +Description: Nested stack for deployment of Metaflow UI (last-updated-date 09/24/2021) |
| 3 | + |
| 4 | +Parameters: |
| 5 | + VPCId: |
| 6 | + Type: AWS::EC2::VPC::Id |
| 7 | + Description: "VPC Id" |
| 8 | + VPCCidrBlock: |
| 9 | + Type: String |
| 10 | + Description: "VPC CIDR block" |
| 11 | + SubnetIds: |
| 12 | + Type: List<AWS::EC2::Subnet::Id> |
| 13 | + Description: "List of VPC subnet Ids" |
| 14 | + SecurityGroup: |
| 15 | + Type: AWS::EC2::SecurityGroup::Id |
| 16 | + Description: "Security group" |
| 17 | + ECSClusterId: |
| 18 | + Type: String |
| 19 | + Description: "ECS cluster Id" |
| 20 | + ECSTaskExecutionRoleId: |
| 21 | + Type: String |
| 22 | + Description: "ECS task execution IAM role Id" |
| 23 | + MetadataSvcECSTaskRoleArn: |
| 24 | + Type: String |
| 25 | + Description: "ECS service IAM role ARN" |
| 26 | + DatabaseHost: |
| 27 | + Type: String |
| 28 | + Description: "Database hostname" |
| 29 | + DatabasePort: |
| 30 | + Type: String |
| 31 | + Default: "5432" |
| 32 | + Description: "Database port" |
| 33 | + DatabaseUser: |
| 34 | + Type: String |
| 35 | + Default: "master" |
| 36 | + Description: "Database user" |
| 37 | + DatabasePassword: |
| 38 | + Type: String |
| 39 | + Description: "Database password" |
| 40 | + DatabaseName: |
| 41 | + Type: String |
| 42 | + Default: "metaflow" |
| 43 | + Description: "Database name" |
| 44 | + |
| 45 | +Mappings: |
| 46 | + ServiceInfoUI: |
| 47 | + ServiceName: |
| 48 | + value: "metaflow-ui-service" |
| 49 | + ImageUrl: |
| 50 | + value: "netflixoss/metaflow_metadata_service" |
| 51 | + ContainerPort: |
| 52 | + value: 8083 |
| 53 | + ContainerCpu: |
| 54 | + value: 512 |
| 55 | + ContainerMemory: |
| 56 | + value: 1024 |
| 57 | + DesiredCount: |
| 58 | + value: 1 |
| 59 | + |
| 60 | +Resources: |
| 61 | + # Ingress rules |
| 62 | + |
| 63 | + IngressRuleUIService: |
| 64 | + Type: "AWS::EC2::SecurityGroupIngress" |
| 65 | + Properties: |
| 66 | + Description: "Allow API Calls Internally (UI service)" |
| 67 | + GroupId: !Ref SecurityGroup |
| 68 | + IpProtocol: tcp |
| 69 | + FromPort: !FindInMap ["ServiceInfoUI", "ContainerPort", "value"] |
| 70 | + ToPort: !FindInMap ["ServiceInfoUI", "ContainerPort", "value"] |
| 71 | + CidrIp: !Ref VPCCidrBlock |
| 72 | + |
| 73 | + # Load balancer |
| 74 | + |
| 75 | + ALBUISecurityGroup: |
| 76 | + Type: AWS::EC2::SecurityGroup |
| 77 | + Properties: |
| 78 | + GroupDescription: Access to the public facing load balancer |
| 79 | + VpcId: !Ref VPCId |
| 80 | + SecurityGroupIngress: |
| 81 | + # Allow access to ALB from anywhere on the internet |
| 82 | + - CidrIp: 0.0.0.0/0 |
| 83 | + IpProtocol: -1 |
| 84 | + ALBUI: |
| 85 | + Type: AWS::ElasticLoadBalancingV2::LoadBalancer |
| 86 | + Properties: |
| 87 | + Scheme: internet-facing |
| 88 | + Type: application |
| 89 | + Subnets: !Ref SubnetIds |
| 90 | + SecurityGroups: [!Ref ALBUISecurityGroup] |
| 91 | + ALBUIListener: |
| 92 | + Type: AWS::ElasticLoadBalancingV2::Listener |
| 93 | + DependsOn: |
| 94 | + - ALBUI |
| 95 | + Properties: |
| 96 | + DefaultActions: |
| 97 | + - TargetGroupArn: !Ref ALBUITargetGroupUIService |
| 98 | + Type: "forward" |
| 99 | + LoadBalancerArn: !Ref ALBUI |
| 100 | + Port: 80 |
| 101 | + Protocol: HTTP |
| 102 | + ALBUITargetGroupUIService: |
| 103 | + Type: AWS::ElasticLoadBalancingV2::TargetGroup |
| 104 | + Properties: |
| 105 | + HealthCheckIntervalSeconds: 6 |
| 106 | + HealthCheckPath: /ping |
| 107 | + HealthCheckProtocol: HTTP |
| 108 | + HealthCheckTimeoutSeconds: 5 |
| 109 | + HealthyThresholdCount: 2 |
| 110 | + TargetType: ip |
| 111 | + Port: !FindInMap ["ServiceInfoUI", "ContainerPort", "value"] |
| 112 | + Protocol: HTTP |
| 113 | + UnhealthyThresholdCount: 2 |
| 114 | + VpcId: !Ref VPCId |
| 115 | + |
| 116 | + # Coudfront distribution |
| 117 | + |
| 118 | + CloudFrontDistribution: |
| 119 | + Type: AWS::CloudFront::Distribution |
| 120 | + DependsOn: |
| 121 | + - ALBUI |
| 122 | + Properties: |
| 123 | + DistributionConfig: |
| 124 | + Origins: |
| 125 | + - DomainName: !GetAtt "ALBUI.DNSName" |
| 126 | + Id: !Ref ALBUI |
| 127 | + CustomOriginConfig: |
| 128 | + HTTPPort: 80 |
| 129 | + OriginProtocolPolicy: http-only |
| 130 | + OriginKeepaliveTimeout: 60 |
| 131 | + OriginReadTimeout: 30 |
| 132 | + OriginSSLProtocols: |
| 133 | + - TLSv1 |
| 134 | + - TLSv1.1 |
| 135 | + - TLSv1.2 |
| 136 | + - SSLv3 |
| 137 | + Enabled: true |
| 138 | + HttpVersion: http2 |
| 139 | + DefaultCacheBehavior: |
| 140 | + AllowedMethods: |
| 141 | + - GET |
| 142 | + - HEAD |
| 143 | + - DELETE |
| 144 | + - OPTIONS |
| 145 | + - PATCH |
| 146 | + - POST |
| 147 | + - PUT |
| 148 | + Compress: true |
| 149 | + DefaultTTL: 0 |
| 150 | + MinTTL: 0 |
| 151 | + MaxTTL: 0 |
| 152 | + SmoothStreaming: false |
| 153 | + TargetOriginId: !Ref ALBUI |
| 154 | + ForwardedValues: |
| 155 | + QueryString: true |
| 156 | + Cookies: |
| 157 | + Forward: none |
| 158 | + ViewerProtocolPolicy: redirect-to-https |
| 159 | + CacheBehaviors: |
| 160 | + - AllowedMethods: |
| 161 | + - GET |
| 162 | + - HEAD |
| 163 | + - DELETE |
| 164 | + - OPTIONS |
| 165 | + - PATCH |
| 166 | + - POST |
| 167 | + - PUT |
| 168 | + Compress: false |
| 169 | + PathPattern: /api/* |
| 170 | + DefaultTTL: 0 |
| 171 | + MinTTL: 0 |
| 172 | + MaxTTL: 0 |
| 173 | + SmoothStreaming: false |
| 174 | + TargetOriginId: !Ref ALBUI |
| 175 | + ForwardedValues: |
| 176 | + QueryString: true |
| 177 | + Cookies: |
| 178 | + Forward: none |
| 179 | + ViewerProtocolPolicy: redirect-to-https |
| 180 | + PriceClass: PriceClass_All |
| 181 | + IPV6Enabled: true |
| 182 | + |
| 183 | + # ESC Cluster task definition & service |
| 184 | + |
| 185 | + TaskDefinitionUIService: |
| 186 | + Type: AWS::ECS::TaskDefinition |
| 187 | + Properties: |
| 188 | + Family: !FindInMap ["ServiceInfoUI", "ServiceName", "value"] |
| 189 | + Cpu: !FindInMap ["ServiceInfoUI", "ContainerCpu", "value"] |
| 190 | + Memory: !FindInMap ["ServiceInfoUI", "ContainerMemory", "value"] |
| 191 | + NetworkMode: awsvpc |
| 192 | + RequiresCompatibilities: |
| 193 | + - FARGATE |
| 194 | + ExecutionRoleArn: !Ref ECSTaskExecutionRoleId |
| 195 | + TaskRoleArn: !Ref MetadataSvcECSTaskRoleArn |
| 196 | + ContainerDefinitions: |
| 197 | + - Name: !FindInMap ["ServiceInfoUI", "ServiceName", "value"] |
| 198 | + Environment: |
| 199 | + - Name: "MF_METADATA_DB_HOST" |
| 200 | + Value: !Ref DatabaseHost |
| 201 | + - Name: "MF_METADATA_DB_PORT" |
| 202 | + Value: !Ref DatabasePort |
| 203 | + - Name: "MF_METADATA_DB_USER" |
| 204 | + Value: !Ref DatabaseUser |
| 205 | + - Name: "MF_METADATA_DB_PSWD" |
| 206 | + Value: !Ref DatabasePassword |
| 207 | + - Name: "MF_METADATA_DB_NAME" |
| 208 | + Value: !Ref DatabaseName |
| 209 | + - Name: "UI_ENABLED" |
| 210 | + Value: "1" |
| 211 | + Cpu: !FindInMap ["ServiceInfoUI", "ContainerCpu", "value"] |
| 212 | + Memory: !FindInMap ["ServiceInfoUI", "ContainerMemory", "value"] |
| 213 | + Image: !FindInMap ["ServiceInfoUI", "ImageUrl", "value"] |
| 214 | + Command: |
| 215 | + [ |
| 216 | + "/opt/latest/bin/python3", |
| 217 | + "-m", |
| 218 | + "services.ui_backend_service.ui_server", |
| 219 | + ] |
| 220 | + PortMappings: |
| 221 | + - ContainerPort: |
| 222 | + !FindInMap ["ServiceInfoUI", "ContainerPort", "value"] |
| 223 | + LogConfiguration: |
| 224 | + LogDriver: awslogs |
| 225 | + Options: |
| 226 | + awslogs-group: |
| 227 | + !Join [ |
| 228 | + "", |
| 229 | + [ |
| 230 | + "/ecs/", |
| 231 | + !Ref "AWS::StackName", |
| 232 | + "-", |
| 233 | + !FindInMap ["ServiceInfoUI", "ServiceName", "value"], |
| 234 | + ], |
| 235 | + ] |
| 236 | + awslogs-region: !Ref "AWS::Region" |
| 237 | + awslogs-stream-prefix: "ecs" |
| 238 | + ServiceLogGroupUIService: |
| 239 | + Type: AWS::Logs::LogGroup |
| 240 | + Properties: |
| 241 | + LogGroupName: |
| 242 | + !Join [ |
| 243 | + "", |
| 244 | + [ |
| 245 | + "/ecs/", |
| 246 | + !Ref "AWS::StackName", |
| 247 | + "-", |
| 248 | + !FindInMap ["ServiceInfoUI", "ServiceName", "value"], |
| 249 | + ], |
| 250 | + ] |
| 251 | + ECSFargateServiceUIService: |
| 252 | + Type: AWS::ECS::Service |
| 253 | + DependsOn: ALBUIListener |
| 254 | + Properties: |
| 255 | + ServiceName: !FindInMap ["ServiceInfoUI", "ServiceName", "value"] |
| 256 | + Cluster: !Ref ECSClusterId |
| 257 | + LaunchType: FARGATE |
| 258 | + DeploymentConfiguration: |
| 259 | + MaximumPercent: 200 |
| 260 | + MinimumHealthyPercent: 75 |
| 261 | + DesiredCount: !FindInMap ["ServiceInfoUI", "DesiredCount", "value"] |
| 262 | + NetworkConfiguration: |
| 263 | + AwsvpcConfiguration: |
| 264 | + AssignPublicIp: ENABLED |
| 265 | + SecurityGroups: |
| 266 | + - !Ref SecurityGroup |
| 267 | + Subnets: !Ref SubnetIds |
| 268 | + TaskDefinition: !Ref TaskDefinitionUIService |
| 269 | + LoadBalancers: |
| 270 | + - ContainerName: !FindInMap ["ServiceInfoUI", "ServiceName", "value"] |
| 271 | + ContainerPort: !FindInMap ["ServiceInfoUI", "ContainerPort", "value"] |
| 272 | + TargetGroupArn: !Ref ALBUITargetGroupUIService |
| 273 | + |
| 274 | +Outputs: |
| 275 | + ServiceUrl: |
| 276 | + Description: "ALB URL for Metadata UI (Open to Public Access)" |
| 277 | + Value: !Sub "http://${ALBUI.DNSName}/" |
| 278 | + ServiceCloudfrontUrl: |
| 279 | + Description: "Cloudfront URL for Metadata UI (Open to Public Access)" |
| 280 | + Value: !Sub "https://${CloudFrontDistribution.DomainName}/" |
0 commit comments