From 71710d40c9fca7d35665f59bd82701dd04197bed Mon Sep 17 00:00:00 2001 From: Joseph Manley Date: Sun, 10 Nov 2019 18:45:38 -0500 Subject: [PATCH] Update ReadMe.md; Create Network LoadBalancer --- ReadMe.md | 6 +- cloudformation/nakama/task.yaml | 2 + cloudformation/nakama/top.yaml | 133 +++++++++++++++++++++++++------- 3 files changed, 110 insertions(+), 31 deletions(-) diff --git a/ReadMe.md b/ReadMe.md index ed61153..660f7b3 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -16,9 +16,8 @@ Parameters, `DatabaseUsername`, `DatabasePassword`, `DatabaseEndpoint`, and `Dat ## To Do -- [ ] Load Balancing - - [x] Portal - - [ ] Application +- [x] Load Balancing + - [ ] [Clustering](https://heroiclabs.com/nakama-enterprise/) - [ ] Auto Scaling - [x] Dynamic Port Routing - [x] HTTPS @@ -29,3 +28,4 @@ Parameters, `DatabaseUsername`, `DatabasePassword`, `DatabaseEndpoint`, and `Dat - [ ] Custom security keys - [ ] Formatted Launch Parameters - [ ] Informative `ReadMe.md` +- [ ] Load Server Modules diff --git a/cloudformation/nakama/task.yaml b/cloudformation/nakama/task.yaml index d090743..7f50567 100644 --- a/cloudformation/nakama/task.yaml +++ b/cloudformation/nakama/task.yaml @@ -65,6 +65,8 @@ Resources: Image: "heroiclabs/nakama:2.7.0" MemoryReservation: 800 PortMappings: + - HostPort: 0 + ContainerPort: 7348 - HostPort: 0 ContainerPort: 7349 - HostPort: 0 diff --git a/cloudformation/nakama/top.yaml b/cloudformation/nakama/top.yaml index 2b73265..bf52425 100644 --- a/cloudformation/nakama/top.yaml +++ b/cloudformation/nakama/top.yaml @@ -126,9 +126,103 @@ Resources: #----------------- # Load Balancing #----------------- + + #-- Network Load Balancer --# + PublicNLB: + Type: AWS::ElasticLoadBalancingV2::LoadBalancer + Properties: + Type: network + LoadBalancerAttributes: + - Key: deletion_protection.enabled + Value: false + Scheme: internet-facing + Subnets: !Split [",", !Ref PublicSubnets] + Tags: + - Key: Name + Value: !Sub "Nakama-${environment}-NLB" + - Key: environment + Value: !Ref environment + + # Target group for HTTP api + HttpApiTargetGroup: + Type: AWS::ElasticLoadBalancingV2::TargetGroup + Properties: + Port: 7350 + Protocol: TCP + TargetGroupAttributes: + - Key: deregistration_delay.timeout_seconds + Value: '20' + VpcId: !Ref 'VpcId' + Tags: + - Key: Name + Value: !Sub 'nakama-http-${release}' + + # Listener for HTTP + HttpApiNlbListener: + Type: AWS::ElasticLoadBalancingV2::Listener + Properties: + DefaultActions: + - Type: forward + TargetGroupArn: !Ref HttpApiTargetGroup + LoadBalancerArn: !Ref PublicNLB + Port: 7350 + Protocol: TCP + + # Target group for gRPC API + GRpcApiTargetGroup: + Type: AWS::ElasticLoadBalancingV2::TargetGroup + Properties: + Port: 7349 + Protocol: TCP_UDP + TargetGroupAttributes: + - Key: deregistration_delay.timeout_seconds + Value: '20' + VpcId: !Ref 'VpcId' + Tags: + - Key: Name + Value: !Sub 'nakama-GRpc-${release}' + + # Listener for gRPC API + GRpcNlbListener: + Type: AWS::ElasticLoadBalancingV2::Listener + Properties: + DefaultActions: + - Type: forward + TargetGroupArn: !Ref GRpcApiTargetGroup + LoadBalancerArn: !Ref PublicNLB + Port: 7349 + Protocol: TCP_UDP + + # Target group for gRPC embeded console + GRpcEApiTargetGroup: + Type: AWS::ElasticLoadBalancingV2::TargetGroup + Properties: + Port: 7348 + Protocol: TCP_UDP + TargetGroupAttributes: + - Key: deregistration_delay.timeout_seconds + Value: '20' + VpcId: !Ref 'VpcId' + Tags: + - Key: Name + Value: !Sub 'nakama-GRpc-${release}' + + # Listener for gRPC embeded console + GRpcENlbListener: + Type: AWS::ElasticLoadBalancingV2::Listener + Properties: + DefaultActions: + - Type: forward + TargetGroupArn: !Ref GRpcEApiTargetGroup + LoadBalancerArn: !Ref PublicNLB + Port: 7348 + Protocol: TCP_UDP + + #-- Application Load Balancer --# PublicALB: Type: AWS::ElasticLoadBalancingV2::LoadBalancer Properties: + Type: application LoadBalancerAttributes: - Key: deletion_protection.enabled Value: false @@ -176,33 +270,6 @@ Resources: ToPort: "65535" CidrIp: 0.0.0.0/0 - # Target group for HTTP api - HttpApiTargetGroup: - Type: AWS::ElasticLoadBalancingV2::TargetGroup - Properties: - Port: 7350 - Protocol: HTTP - TargetGroupAttributes: - - Key: deregistration_delay.timeout_seconds - Value: '20' - VpcId: !Ref 'VpcId' - Tags: - - Key: Name - Value: !Sub 'nakama-http-${release}' - - # HTTPS for HTTP Api - HttpApiAlbListener: - Type: AWS::ElasticLoadBalancingV2::Listener - Properties: - Certificates: - - CertificateArn: !Ref PortalCertificate - DefaultActions: - - Type: forward - TargetGroupArn: !Ref HttpApiTargetGroup - LoadBalancerArn: !Ref PublicALB - Port: 7350 - Protocol: HTTPS - # Target group for admin portal port AdminPortalTargetGroup: Type: AWS::ElasticLoadBalancingV2::TargetGroup @@ -254,6 +321,7 @@ Resources: LoadBalancerArn: !Ref PublicALB Port: 80 Protocol: HTTP + #------------------- # ECS Task & Service @@ -280,4 +348,13 @@ Resources: LoadBalancers: - ContainerName: "nakama" ContainerPort: 7351 - TargetGroupArn: !Ref 'AdminPortalTargetGroup' \ No newline at end of file + TargetGroupArn: !Ref AdminPortalTargetGroup + - ContainerName: "nakama" + ContainerPort: 7350 + TargetGroupArn: !Ref HttpApiTargetGroup + - ContainerName: "nakama" + ContainerPort: 7349 + TargetGroupArn: !Ref GRpcApiTargetGroup + - ContainerName: "nakama" + ContainerPort: 7348 + TargetGroupArn: !Ref GRpcEApiTargetGroup \ No newline at end of file