diff --git a/cloudformation/antmedia-aws-gpu-autoscale-template.yaml b/cloudformation/antmedia-aws-gpu-autoscale-template.yaml new file mode 100644 index 00000000..27705ec8 --- /dev/null +++ b/cloudformation/antmedia-aws-gpu-autoscale-template.yaml @@ -0,0 +1,864 @@ +AWSTemplateFormatVersion: 2010-09-09 +Description: >- + Ant Media Server AutoScaling CloudFormation Templates. + If you have any questions, please just drop a line to contact (at) antmedia.io +Parameters: + VpcCidrBlock: + Description: 'CIDR value for Wavelength Network' + Type: String + MinLength: '9' + MaxLength: '18' + Default: 10.0.0.0/16 + AllowedPattern: '(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})' + ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x. + OriginCidrBlock: + Description: 'CIDR value of Origin' + Type: String + MinLength: '9' + MaxLength: '18' + Default: 10.0.1.0/24 + AllowedPattern: '(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})' + EdgeCidrBlock: + Description: 'CIDR value of Edge' + Type: String + MinLength: '9' + MaxLength: '18' + Default: 10.0.2.0/24 + AllowedPattern: '(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})' + EdgeInstanceType: + Description: Ant Media Server Edge EC2 instance type + Type: String + Default: g5.4xlarge + AllowedValues: + - p2.xlarge + - p2.8xlarge + - p2.16xlarge + - p3.2xlarge + - p3.8xlarge + - p3.16xlarge + - p3dn.24xlarge + - g4dn.xlarge + - g4dn.2xlarge + - g4dn.4xlarge + - g4dn.8xlarge + - g4dn.12xlarge + - g4dn.16xlarge + - g5.xlarge + - g5.2xlarge + - g5.4xlarge + - g5.8xlarge + - g5.12xlarge + - g5.16xlarge + ConstraintDescription: must be a valid EC2 instance type. + + OriginInstanceType: + Description: Ant Media Server Origin EC2 instance type + Type: String + Default: g5.4xlarge + AllowedValues: + - p2.xlarge + - p2.8xlarge + - p2.16xlarge + - p3.2xlarge + - p3.8xlarge + - p3.16xlarge + - p3dn.24xlarge + - g4dn.xlarge + - g4dn.2xlarge + - g4dn.4xlarge + - g4dn.8xlarge + - g4dn.12xlarge + - g4dn.16xlarge + - g5.xlarge + - g5.2xlarge + - g5.4xlarge + - g5.8xlarge + - g5.12xlarge + - g5.16xlarge + ConstraintDescription: must be a valid EC2 instance type. + + MongoDBInstanceType: + Description: Ant Media MongoDB EC2 instance type + Type: String + Default: c5.xlarge + AllowedValues: + - c5.large + - c5.xlarge + - c5.2xlarge + - c5.4xlarge + - c5.9xlarge + - c5.18xlarge + - m5.large + - m5.xlarge + - m5.2xlarge + - m5.4xlarge + - m5.12xlarge + - m5.24xlarge + - r5.large + - r5.xlarge + - r5.2xlarge + - r5.4xlarge + - r5.12xlarge + - r5.24xlarge + - m5a.large + - m5a.xlarge + - m5a.2xlarge + - m5a.4xlarge + - m5a.12xlarge + - m5a.24xlarge + - r5a.large + - r5a.xlarge + - r5a.2xlarge + - r5a.4xlarge + - r5a.12xlarge + - r5a.24xlarge + KeyName: + Description: Name of an existing EC2 KeyPair to enable SSH access to the instances. If there is no value here, you must create an ssh key (EC2 > Key Pairs). + Type: 'AWS::EC2::KeyPair::KeyName' + MinLength: '1' + MaxLength: '255' + AllowedPattern: '[\x20-\x7E]*' + ConstraintDescription: can contain only ASCII characters. + SSHLocation: + Description: The IP address range that can be used to SSH to the EC2 instances + Type: String + MinLength: '9' + MaxLength: '18' + Default: 0.0.0.0/0 + AllowedPattern: '(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})' + ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x. + Email: + Description: EMail address to notify if there are any scaling operations + Type: String + AllowedPattern: >- + ([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?) + ConstraintDescription: must be a valid email address. + AntMediaOriginCapacity: + Default: '1' + Description: The initial number of Ant Media Origin instances + Type: Number + MinValue: '1' + MaxValue: '1000' + AntMediaOriginCapacityMax: + Default: '10' + Description: The initial number of Ant Media Origin instances + Type: Number + ConstraintDescription: must be between 2 and 20 EC2 instances. + AntMediaEdgeCapacity: + Default: '2' + Description: The initial number of Ant Media Edge instances + Type: Number + MinValue: '1' + MaxValue: '1000' + AntMediaEdgeCapacityMax: + Default: '10' + Description: The initial number of Ant Media Edge instances + Type: Number + ConstraintDescription: must be between 2 and 20 EC2 instances. + CPUPolicyTargetValue: + Type: Number + Default: 60.0 + Description: This parameter for creates new Instances when CPU load exceed to %60. + LoadBalancerCertificateArn: + Description: 'Amazon Resource Name (ARN) of the certificate to associate with the load balancer. If you do not have the SSL certificate, please check this guide: https://antmedia.io/ant-media-server-cloudformation-installation/ ' + Type: String + Default: '' + DiskSize: + Default: '16' + Description: Disk size of instances + Type: Number + MinValue: '16' + MaxValue: '1000' + +Resources: + DescribeImagesRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Version: '2012-10-17' + Statement: + - Action: sts:AssumeRole + Effect: Allow + Principal: + Service: lambda.amazonaws.com + ManagedPolicyArns: + - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole + Policies: + - PolicyName: DescribeImages + PolicyDocument: + Version: '2012-10-17' + Statement: + - Action: ec2:DescribeImages + Effect: Allow + Resource: "*" + AMSGetLatestAMI: + Type: AWS::Lambda::Function + Properties: + Runtime: python3.11 + Handler: index.handler + Role: !Sub ${DescribeImagesRole.Arn} + Timeout: 60 + Code: + ZipFile: | + import boto3 + import cfnresponse + import json + import traceback + + def handler(event, context): + try: + response = boto3.client('ec2').describe_images( + Filters=[ + {'Name': 'product-code', 'Values': [event['ResourceProperties']['ProductId']]}, + {'Name': 'name', 'Values': [event['ResourceProperties']['Name']]}, + {'Name': 'architecture', 'Values': [event['ResourceProperties']['Architecture']]}, + {'Name': 'root-device-type', 'Values': ['ebs']}, + ], + ) + + amis = sorted(response['Images'], + key=lambda x: x['CreationDate'], + reverse=True) + id = amis[0]['ImageId'] + + cfnresponse.send(event, context, cfnresponse.SUCCESS, {}, id) + except: + traceback.print_last() + cfnresponse.send(event, context, cfnresponse.FAIL, {}, "ok") + UbuntuGetLatestAMI: + Type: AWS::Lambda::Function + Properties: + Runtime: python3.11 + Handler: index.handler + Role: !Sub ${DescribeImagesRole.Arn} + Timeout: 60 + Code: + ZipFile: | + import boto3 + import cfnresponse + import json + import traceback + + def handler(event, context): + try: + response = boto3.client('ec2').describe_images( + Owners=[event['ResourceProperties']['Owner']], + Filters=[ + {'Name': 'name', 'Values': [event['ResourceProperties']['Name']]}, + {'Name': 'architecture', 'Values': [event['ResourceProperties']['Architecture']]}, + {'Name': 'root-device-type', 'Values': ['ebs']}, + ], + ) + + amis = sorted(response['Images'], + key=lambda x: x['CreationDate'], + reverse=True) + id = amis[0]['ImageId'] + + cfnresponse.send(event, context, cfnresponse.SUCCESS, {}, id) + except: + traceback.print_last() + cfnresponse.send(event, context, cfnresponse.FAIL, {}, "ok") + + AntMediaAmi: + Type: Custom::FindAMI + Properties: + ServiceToken: !Sub ${AMSGetLatestAMI.Arn} + ProductId: "8kf9kapq2qbo37fuekp8k7o6r" + Name: "AntMedia-AWS-Marketplace-GPU-*" + Architecture: "x86_64" + + UbuntuAmi: + Type: Custom::FindAMI + Properties: + ServiceToken: !Sub ${UbuntuGetLatestAMI.Arn} + Owner: "099720109477" + Name: "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*" + Architecture: "x86_64" + + AntMediaVPC: + Type: AWS::EC2::VPC + Properties: + CidrBlock: !Ref VpcCidrBlock + EnableDnsHostnames: true + EnableDnsSupport: true + Tags: + - Key: Name + Value: !Sub ${AWS::StackName}-AntMedia-VPC + + OriginZone: + Type: AWS::EC2::Subnet + DependsOn: AntMediaVPC + Properties: + VpcId: !Ref AntMediaVPC + CidrBlock: !Ref OriginCidrBlock + MapPublicIpOnLaunch: true + AvailabilityZone: + Fn::Select: + - 0 + - Fn::GetAZs: "" + Tags: + - Key: Name + Value: !Sub ${AWS::StackName}-AntMedia-Origin-Subnet + + EdgeZone: + Type: AWS::EC2::Subnet + DependsOn: AntMediaVPC + Properties: + VpcId: !Ref AntMediaVPC + CidrBlock: !Ref EdgeCidrBlock + MapPublicIpOnLaunch: true + AvailabilityZone: + Fn::Select: + - 1 + - Fn::GetAZs: "" + Tags: + - Key: Name + Value: !Sub ${AWS::StackName}-AntMedia-Edge-Subnet + + DefaultGateway: + Type: AWS::EC2::InternetGateway + + InternetGatewayAttachment: + Type: AWS::EC2::VPCGatewayAttachment + Properties: + InternetGatewayId: !Ref DefaultGateway + VpcId: !Ref AntMediaVPC + + RouteTable: + Type: AWS::EC2::RouteTable + Properties: + VpcId: !Ref AntMediaVPC + Tags: + - Key: Name + Value: !Sub ${AWS::StackName}-AntMedia-Route-Table + + DefaultRoute: + Type: AWS::EC2::Route + DependsOn: InternetGatewayAttachment + Properties: + RouteTableId: !Ref RouteTable + GatewayId: !Ref DefaultGateway + DestinationCidrBlock: 0.0.0.0/0 + + SubnetRouteTableAssociationOrigin: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + RouteTableId: !Ref RouteTable + SubnetId: !Ref OriginZone + + SubnetRouteTableAssociationEdge: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + RouteTableId: !Ref RouteTable + SubnetId: !Ref EdgeZone + + + NotificationTopic: + Type: 'AWS::SNS::Topic' + DependsOn: + - DBInstance + Properties: + Subscription: + - Endpoint: !Ref Email + Protocol: email + + RTMPLoadBalancer: + Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer' + DependsOn: + - InternetGatewayAttachment + Properties: + Subnets: + - !Ref OriginZone + 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: + HealthCheckIntervalSeconds: 30 + HealthyThresholdCount: 3 + Port: 1935 + Protocol: TCP + UnhealthyThresholdCount: 3 + VpcId: !Ref AntMediaVPC + RTMPSecurityGroup: + Type: 'AWS::EC2::SecurityGroup' + Properties: + GroupDescription: 'Ant Media Server RTMP Load Balancer Security Group' + SecurityGroupIngress: + - 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 AntMediaVPC + + OriginGroup: + Type: 'AWS::AutoScaling::AutoScalingGroup' + DependsOn: + - LaunchTemplateOrigin + Properties: + VPCZoneIdentifier: + - !Ref OriginZone + LaunchTemplate: + LaunchTemplateName: !Sub ${AWS::StackName}-AntMedia-LaunchTemplateOrigin + Version: !GetAtt 'LaunchTemplateOrigin.LatestVersionNumber' + MinSize: !Ref AntMediaOriginCapacity + MaxSize: !Ref AntMediaOriginCapacityMax + DesiredCapacity: !Ref AntMediaOriginCapacity + TargetGroupARNs: + - !Ref ALBTargetGroupOrigin + - !Ref RTMPTargetGroup + Tags: + - Key: Name + Value: Antmedia-Origin + PropagateAtLaunch: 'true' + CreationPolicy: + ResourceSignal: + Timeout: PT15M + Count: !Ref AntMediaOriginCapacity + UpdatePolicy: + AutoScalingRollingUpdate: + MinInstancesInService: '1' + MaxBatchSize: '1' + PauseTime: PT15M + WaitOnResourceSignals: 'true' + NotificationConfiguration: + TopicARN: !Ref NotificationTopic + NotificationTypes: + - 'autoscaling:EC2_INSTANCE_LAUNCH' + - 'autoscaling:EC2_INSTANCE_LAUNCH_ERROR' + - 'autoscaling:EC2_INSTANCE_TERMINATE' + - 'autoscaling:EC2_INSTANCE_TERMINATE_ERROR' + + LaunchTemplateOrigin: + Type: 'AWS::EC2::LaunchTemplate' + Properties: + LaunchTemplateName: !Sub ${AWS::StackName}-AntMedia-LaunchTemplateOrigin + LaunchTemplateData: + InstanceType: !Ref OriginInstanceType + KeyName: !Ref KeyName + ImageId: !Ref AntMediaAmi + SecurityGroupIds: + - !GetAtt "InstanceSecurityGroup.GroupId" + BlockDeviceMappings: + - DeviceName: /dev/sda1 + Ebs: + VolumeSize: !Ref DiskSize + VolumeType: gp2 + DeleteOnTermination: true + UserData: + Fn::Base64: !Sub | + #!/bin/bash + 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 + apt-get install -y python3-setuptools + mkdir -p /opt/aws/bin + wget https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz + python3 -m easy_install --script-dir /opt/aws/bin aws-cfn-bootstrap-py3-latest.tar.gz + /opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource OriginGroup --region ${AWS::Region} + TagSpecifications: + - ResourceType: instance + Tags: + - Key: Name + Value: OriginInstance + TagSpecifications: + - ResourceType: launch-template + Tags: + - Key: Name + Value: !Sub ${AWS::StackName}-AntMedia-LaunchTemplateOrigin + + EdgeGroup: + Type: 'AWS::AutoScaling::AutoScalingGroup' + DependsOn: + - OriginGroup + Properties: + VPCZoneIdentifier: + - !Ref EdgeZone + LaunchTemplate: + LaunchTemplateName: !Sub ${AWS::StackName}-AntMedia-LaunchTemplateEdge + Version: !GetAtt 'LaunchTemplateEdge.LatestVersionNumber' + MinSize: !Ref AntMediaEdgeCapacity + MaxSize: !Ref AntMediaEdgeCapacityMax + DesiredCapacity: !Ref AntMediaEdgeCapacity + TargetGroupARNs: + - !Ref ALBTargetGroupEdge + Tags: + - Key: Name + Value: Antmedia-Edge + PropagateAtLaunch: 'true' + CreationPolicy: + ResourceSignal: + Timeout: PT15M + Count: !Ref AntMediaEdgeCapacity + UpdatePolicy: + AutoScalingRollingUpdate: + MinInstancesInService: '1' + MaxBatchSize: '1' + PauseTime: PT15M + WaitOnResourceSignals: 'true' + NotificationConfiguration: + TopicARN: !Ref NotificationTopic + NotificationTypes: + - 'autoscaling:EC2_INSTANCE_LAUNCH' + - 'autoscaling:EC2_INSTANCE_LAUNCH_ERROR' + - 'autoscaling:EC2_INSTANCE_TERMINATE' + - 'autoscaling:EC2_INSTANCE_TERMINATE_ERROR' + + LaunchTemplateEdge: + Type: 'AWS::EC2::LaunchTemplate' + Properties: + LaunchTemplateName: !Sub ${AWS::StackName}-AntMedia-LaunchTemplateEdge + LaunchTemplateData: + InstanceType: !Ref EdgeInstanceType + KeyName: !Ref KeyName + ImageId: !Ref AntMediaAmi + SecurityGroupIds: + - !GetAtt "InstanceSecurityGroup.GroupId" + BlockDeviceMappings: + - DeviceName: /dev/sda1 + Ebs: + VolumeSize: !Ref DiskSize + VolumeType: gp2 + DeleteOnTermination: true + UserData: + Fn::Base64: !Sub | + #!/bin/bash + 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 + apt-get install -y python3-setuptools + mkdir -p /opt/aws/bin + wget https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz + python3 -m easy_install --script-dir /opt/aws/bin aws-cfn-bootstrap-py3-latest.tar.gz + /opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource EdgeGroup --region ${AWS::Region} + TagSpecifications: + - ResourceType: instance + Tags: + - Key: Name + Value: EdgeInstance + TagSpecifications: + - ResourceType: launch-template + Tags: + - Key: Name + Value: !Sub ${AWS::StackName}-AntMedia-LaunchTemplateEdge + + ELBSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Allows access + VpcId: !Ref AntMediaVPC + SecurityGroupIngress: + - CidrIp: 0.0.0.0/0 + IpProtocol: tcp + FromPort: 80 + ToPort: 80 + Description: Allow 80. Port for Origin Instances + - CidrIp: 0.0.0.0/0 + IpProtocol: tcp + FromPort: 443 + ToPort: 443 + Description: Allow 443. Port for Origin Instances + - CidrIp: 0.0.0.0/0 + IpProtocol: tcp + FromPort: 5080 + ToPort: 5080 + Description: Allow 5080. Port for Edge Instances + - CidrIp: 0.0.0.0/0 + IpProtocol: tcp + FromPort: 5443 + ToPort: 5443 + Description: Allow 5443. Port for Edge Instances + - CidrIp: 0.0.0.0/0 + IpProtocol: tcp + FromPort: 4444 + ToPort: 4444 + Description: Allow 4444. Port for accessing Dashboard + + ApplicationLoadBalancer: + Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer' + DependsOn: + - DBInstance + Properties: + Subnets: + - !Ref OriginZone + - !Ref EdgeZone + SecurityGroups: + - !GetAtt [ ELBSecurityGroup, GroupId ] + ALBListener443: + Type: 'AWS::ElasticLoadBalancingV2::Listener' + Properties: + Certificates: + - CertificateArn: !Ref LoadBalancerCertificateArn + DefaultActions: + - Type: forward + TargetGroupArn: !Ref ALBTargetGroupOrigin + LoadBalancerArn: !Ref ApplicationLoadBalancer + Port: '443' + Protocol: HTTPS + ALBListener5443: + Type: 'AWS::ElasticLoadBalancingV2::Listener' + Properties: + Certificates: + - CertificateArn: !Ref LoadBalancerCertificateArn + DefaultActions: + - Type: forward + TargetGroupArn: !Ref ALBTargetGroupEdge + LoadBalancerArn: !Ref ApplicationLoadBalancer + Port: '5443' + Protocol: HTTPS + ALBListener4444: + Type: 'AWS::ElasticLoadBalancingV2::Listener' + Properties: + Certificates: + - CertificateArn: !Ref LoadBalancerCertificateArn + DefaultActions: + - Type: forward + TargetGroupArn: !Ref ALBTargetGroupOrigin + LoadBalancerArn: !Ref ApplicationLoadBalancer + Port: '4444' + Protocol: HTTPS + ALBListener5080: + Type: 'AWS::ElasticLoadBalancingV2::Listener' + Properties: + DefaultActions: + - Type: forward + TargetGroupArn: !Ref ALBTargetGroupEdge + LoadBalancerArn: !Ref ApplicationLoadBalancer + Port: '5080' + Protocol: HTTP + ALBListener80: + Type: 'AWS::ElasticLoadBalancingV2::Listener' + Properties: + DefaultActions: + - Type: forward + TargetGroupArn: !Ref ALBTargetGroupOrigin + LoadBalancerArn: !Ref ApplicationLoadBalancer + Port: '80' + Protocol: HTTP + ALBTargetGroupOrigin: + Type: 'AWS::ElasticLoadBalancingV2::TargetGroup' + DependsOn: + - DBInstance + Properties: + HealthCheckIntervalSeconds: 30 + HealthCheckTimeoutSeconds: 5 + HealthyThresholdCount: 3 + Port: 5080 + Protocol: HTTP + UnhealthyThresholdCount: 5 + VpcId: !Ref AntMediaVPC + TargetGroupAttributes: + - Key: stickiness.enabled + Value: 'true' + - Key: stickiness.type + Value: lb_cookie + - Key: stickiness.lb_cookie.duration_seconds + Value: '30' + - Key: load_balancing.algorithm.type + Value: least_outstanding_requests + ALBTargetGroupEdge: + Type: 'AWS::ElasticLoadBalancingV2::TargetGroup' + DependsOn: + - DBInstance + Properties: + HealthCheckIntervalSeconds: 30 + HealthCheckTimeoutSeconds: 5 + HealthyThresholdCount: 3 + Port: 5080 + Protocol: HTTP + UnhealthyThresholdCount: 5 + VpcId: !Ref AntMediaVPC + TargetGroupAttributes: + - Key: load_balancing.algorithm.type + Value: least_outstanding_requests + OriginRule: + Type: 'AWS::ElasticLoadBalancingV2::ListenerRule' + Properties: + Actions: + - Type: forward + TargetGroupArn: !Ref ALBTargetGroupOrigin + Conditions: + - Field: query-string + QueryStringConfig: + Values: + - Key: target + Value: origin + ListenerArn: !Ref ALBListener443 + Priority: 1 + EdgeRule: + Type: 'AWS::ElasticLoadBalancingV2::ListenerRule' + Properties: + Actions: + - Type: forward + TargetGroupArn: !Ref ALBTargetGroupEdge + Conditions: + - Field: query-string + QueryStringConfig: + Values: + - Key: target + Value: edge + ListenerArn: !Ref ALBListener443 + Priority: 2 + InstanceSecurityGroup: + Type: 'AWS::EC2::SecurityGroup' + Properties: + GroupDescription: Enable SSH access and HTTP access on the configured port + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: '22' + ToPort: '22' + CidrIp: !Ref SSHLocation + - IpProtocol: tcp + FromPort: '5080' + ToPort: '5080' + CidrIp: !Ref VpcCidrBlock + - IpProtocol: tcp + FromPort: '1935' + ToPort: '1935' + CidrIp: 0.0.0.0/0 + - IpProtocol: udp + FromPort: '50000' + ToPort: '60000' + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: '5000' + ToPort: '5000' + CidrIp: !Ref VpcCidrBlock + VpcId: !Ref AntMediaVPC + + OriginCPUPolicy: + Type: AWS::AutoScaling::ScalingPolicy + Properties: + AutoScalingGroupName: !Ref OriginGroup + PolicyType: TargetTrackingScaling + TargetTrackingConfiguration: + PredefinedMetricSpecification: + PredefinedMetricType: ASGAverageCPUUtilization + TargetValue: !Ref CPUPolicyTargetValue + + EdgeCPUPolicy: + Type: AWS::AutoScaling::ScalingPolicy + Properties: + AutoScalingGroupName: !Ref EdgeGroup + PolicyType: TargetTrackingScaling + TargetTrackingConfiguration: + PredefinedMetricSpecification: + PredefinedMetricType: ASGAverageCPUUtilization + TargetValue: !Ref CPUPolicyTargetValue + + DBEC2SecurityGroup: + Type: 'AWS::EC2::SecurityGroup' + Properties: + VpcId: !Ref AntMediaVPC + GroupDescription: MongoDB SecurityGroup + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: '27017' + ToPort: '27017' + CidrIp: !Ref VpcCidrBlock + - IpProtocol: tcp + FromPort: '22' + ToPort: '22' + CidrIp: !Ref SSHLocation + DBInstance: + Type: 'AWS::EC2::Instance' + DependsOn: + - AMSGetLatestAMI + - UbuntuAmi + - DescribeImagesRole + Properties: + KeyName: !Ref KeyName + ImageId: !Ref UbuntuAmi + InstanceType: !Ref MongoDBInstanceType + SubnetId: !Ref OriginZone + SecurityGroupIds: + - !GetAtt "DBEC2SecurityGroup.GroupId" + Tags: + - Key: Name + Value: Antmedia-MongoDB + UserData: + Fn::Base64: + !Sub | + #!/bin/bash -xe + wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add - + echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list + sudo apt-get update + sudo apt-get install -y mongodb-org python3-pip python3-setuptools + sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mongod.conf + systemctl enable mongod + systemctl restart mongod + +Outputs: + + Dashboard: + Description: Dashboard Login URL + Value: !Join + - '' + - - 'https://' + - !GetAtt + - ApplicationLoadBalancer + - DNSName + + OriginHTTPS: + Description: HTTPS URL of the Ant Media Origin Servers + Value: !Join + - '' + - - 'https://' + - !GetAtt + - ApplicationLoadBalancer + - DNSName + + EdgeHTTPS: + Description: HTTPS URL of the Ant Media Edge Servers + Value: !Join + - '' + - - 'https://' + - !GetAtt + - ApplicationLoadBalancer + - DNSName + - ':5443' + + OriginHTTP: + Description: HTTP URL of the Ant Media Origin Servers + Value: !Join + - '' + - - 'http://' + - !GetAtt + - ApplicationLoadBalancer + - DNSName + + EdgeHTTP: + Description: HTTP URL of the Ant Media Edge Servers + Value: !Join + - '' + - - 'http://' + - !GetAtt + - ApplicationLoadBalancer + - DNSName + - ':5080' + + RTMP: + Description: RTMP URL of the Ant Media Server + Value: !Join + - '' + - - 'rtmp://' + - !GetAtt + - RTMPLoadBalancer + - DNSName +