From 0386f3595dce7ab4f0ffb4a1370f14c08afa6de2 Mon Sep 17 00:00:00 2001 From: Murat Ugur Eminoglu Date: Sun, 3 Apr 2022 22:06:49 +0300 Subject: [PATCH 1/2] Add NLB for RTMP --- .../antmedia-aws-autoscale-template.yaml | 87 +++++++++---------- 1 file changed, 41 insertions(+), 46 deletions(-) diff --git a/cloudformation/antmedia-aws-autoscale-template.yaml b/cloudformation/antmedia-aws-autoscale-template.yaml index e8c53f45..92f1bd33 100644 --- a/cloudformation/antmedia-aws-autoscale-template.yaml +++ b/cloudformation/antmedia-aws-autoscale-template.yaml @@ -238,17 +238,6 @@ Parameters: Type: Number MinValue: '10' MaxValue: '1000' - RTMP: - Description: If you want to install RTMP Load balancer, please select True - Default: false - Type: String - AllowedValues: - - true - - false -Conditions: - CreateRTMPResources: !Equals - - !Ref RTMP - - true Resources: DescribeImagesRole: @@ -329,38 +318,46 @@ Resources: Subscription: - Endpoint: !Ref Email Protocol: email + RTMPLoadBalancer: - Condition: CreateRTMPResources - Type: AWS::ElasticLoadBalancing::LoadBalancer - Properties: - ConnectionDrainingPolicy: - Enabled: true - Timeout: 60 - ConnectionSettings: - IdleTimeout: 60 - CrossZone: true - Listeners: - - InstancePort: 1935 - InstanceProtocol: TCP - LoadBalancerPort: 1935 - Protocol: TCP + Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer' + Description: 'The NLB that handles network traffic coming into the VPC' + Properties: Subnets: !Ref Subnets - SecurityGroups: - - !GetAtt [ RTMPSecurityGroup, GroupId ] - - RTMPSecurityGroup: - Condition: CreateRTMPResources - Type: AWS::EC2::SecurityGroup + Type: 'network' + RTMPListener: + Type: 'AWS::ElasticLoadBalancingV2::Listener' + Properties: + DefaultActions: + - Type: forward + TargetGroupArn: !Ref RTMPTargetGroup + LoadBalancerArn: !Ref RTMPLoadBalancer + Port: '1935' + Protocol: TCP + RTMPTargetGroup: + Type: 'AWS::ElasticLoadBalancingV2::TargetGroup' Properties: - GroupName: Ant Media Server RTMP Load Balancer Security Group - GroupDescription: Allows access + HealthCheckIntervalSeconds: 30 + HealthyThresholdCount: 3 + Port: 1935 + Protocol: TCP + UnhealthyThresholdCount: 3 VpcId: !Ref VpcId + RTMPSecurityGroup: + Type: 'AWS::EC2::SecurityGroup' + Properties: + GroupDescription: 'Ant Media Server RTMP Load Balancer Security Group' SecurityGroupIngress: - - CidrIp: 0.0.0.0/0 - IpProtocol: tcp - FromPort: 1935 - ToPort: 1935 - Description: Allow 1935. Port for Origin Instances + - IpProtocol: tcp + FromPort: '1935' + ToPort: '1935' + CidrIp: '0.0.0.0/0' + SecurityGroupEgress: + - IpProtocol: tcp + FromPort: 0 + ToPort: 65535 + CidrIp: '0.0.0.0/0' + VpcId: !Ref VpcId OriginGroup: Type: 'AWS::AutoScaling::AutoScalingGroup' @@ -374,8 +371,7 @@ Resources: DesiredCapacity: !Ref AntMediaOriginCapacity TargetGroupARNs: - !Ref ALBTargetGroupOrigin - LoadBalancerNames: - - !If [CreateRTMPResources, !Ref RTMPLoadBalancer, !Ref "AWS::NoValue"] + - !Ref RTMPTargetGroup Tags: - Key: Name Value: Antmedia-Origin @@ -459,10 +455,12 @@ Resources: UserData: Fn::Base64: !Sub | #!/bin/bash - wget https://gist.githubusercontent.com/mekya/f8b85706e2ccbc24d6cfea29d64a042e/raw/init.sh -O /usr/local/antmedia/conf/init.sh + touch /usr/local/antmedia/conf/initialized + wget https://raw.githubusercontent.com/ant-media/Scripts/master/init.sh -O /usr/local/antmedia/conf/init.sh sed -i 's/$INSTANCE_ID/${DashboardPassword}/g' /usr/local/antmedia/conf/init.sh - bash /usr/local/antmedia/conf/init.sh bash /usr/local/antmedia/change_server_mode.sh cluster ${DBInstance.PrivateIp} + rm -rf /usr/local/antmedia/conf/initialized + bash /usr/local/antmedia/conf/init.sh cf apt-get update -y apt-get install -y python3-pip apt-get install -y python3-setuptools @@ -567,9 +565,7 @@ Resources: UserData: Fn::Base64: !Sub | #!/bin/bash - wget https://gist.githubusercontent.com/mekya/f8b85706e2ccbc24d6cfea29d64a042e/raw/init.sh -O /usr/local/antmedia/conf/init.sh - sed -i 's/$INSTANCE_ID/${DashboardPassword}/g' /usr/local/antmedia/conf/init.sh - bash /usr/local/antmedia/conf/init.sh + touch /usr/local/antmedia/conf/initialized bash /usr/local/antmedia/change_server_mode.sh cluster ${DBInstance.PrivateIp} apt-get update apt-get install -y python3-pip @@ -836,7 +832,6 @@ Outputs: - ':5080' RTMP: - Condition: CreateRTMPResources Description: RTMP URL of the Ant Media Server Value: !Join - '' From 76aea1d155968cb58c5f40d5dea4a4fef0adbbb9 Mon Sep 17 00:00:00 2001 From: muratugureminoglu Date: Sun, 3 Apr 2022 22:08:11 +0300 Subject: [PATCH 2/2] Update antmedia-aws-autoscale-template.yaml --- cloudformation/antmedia-aws-autoscale-template.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/cloudformation/antmedia-aws-autoscale-template.yaml b/cloudformation/antmedia-aws-autoscale-template.yaml index 92f1bd33..24d7e60b 100644 --- a/cloudformation/antmedia-aws-autoscale-template.yaml +++ b/cloudformation/antmedia-aws-autoscale-template.yaml @@ -321,7 +321,6 @@ Resources: RTMPLoadBalancer: Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer' - Description: 'The NLB that handles network traffic coming into the VPC' Properties: Subnets: !Ref Subnets Type: 'network'