diff --git a/cloudformation/antmedia-aws-autoscale-template.yaml b/cloudformation/antmedia-aws-autoscale-template.yaml index 7e609a08..685dbc7f 100644 --- a/cloudformation/antmedia-aws-autoscale-template.yaml +++ b/cloudformation/antmedia-aws-autoscale-template.yaml @@ -478,11 +478,13 @@ Resources: OriginGroup: Type: 'AWS::AutoScaling::AutoScalingGroup' DependsOn: - - LaunchConfigOrigin + - LaunchTemplateOrigin Properties: VPCZoneIdentifier: - !Ref OriginZone - LaunchConfigurationName: !Ref LaunchConfigOrigin + LaunchTemplate: + LaunchTemplateName: !Sub ${AWS::StackName}-AntMedia-LaunchTemplateOrigin + Version: !GetAtt 'LaunchTemplateOrigin.LatestVersionNumber' MinSize: !Ref AntMediaOriginCapacity MaxSize: !Ref AntMediaOriginCapacityMax DesiredCapacity: !Ref AntMediaOriginCapacity @@ -510,91 +512,57 @@ Resources: - 'autoscaling:EC2_INSTANCE_LAUNCH_ERROR' - 'autoscaling:EC2_INSTANCE_TERMINATE' - 'autoscaling:EC2_INSTANCE_TERMINATE_ERROR' - LaunchConfigOrigin: - Type: 'AWS::AutoScaling::LaunchConfiguration' - DependsOn: - - ApplicationLoadBalancer - Metadata: - Comment: Install a simple application - 'AWS::CloudFormation::Init': - configSets: - setup: - - "configure_cfn" - configure_cfn: - files: - /etc/cfn/cfn-hup.conf: - content: !Sub | - [main] - stack=${AWS::StackId} - region=${AWS::Region} - verbose=true - interval=5 - mode: "000400" - owner: root - group: root - /etc/cfn/hooks.d/cfn-auto-reloader.conf: - content: !Sub | - [cfn-auto-reloader-hook] - triggers=post.update - path=Resources.LaunchConfigOrigin.Metadata.AWS::CloudFormation::Init - action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource LaunchConfigOrigin --configsets setup --region ${AWS::Region} - mode: "000400" - owner: root - group: root - /lib/systemd/system/cfn-hup.service: - content: !Sub | - [Unit] - Description=cfn-hup daemon - - [Service] - Type=simple - ExecStart=/opt/aws/bin/cfn-hup - Restart=always - - [Install] - WantedBy=multi-user.target - mode: "000400" - owner: root - group: root - - Properties: - KeyName: !Ref KeyName - ImageId: !Ref AntMediaAmi - SecurityGroups: - - !Ref InstanceSecurityGroup - InstanceType: !Ref OriginInstanceType - BlockDeviceMappings: - - DeviceName: /dev/sda1 - Ebs: - VolumeSize: !Ref DiskSize - VolumeType: gp2 - DeleteOnTermination: true - UserData: - Fn::Base64: !Sub | - #!/bin/bash - 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/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 - 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-init -v --stack ${AWS::StackName} --resource LaunchConfigOrigin --configsets setup --region ${AWS::Region} - /opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource OriginGroup --region ${AWS::Region} + + 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 + 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 + 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: - - LaunchConfigEdge + - LaunchTemplateEdge Properties: VPCZoneIdentifier: - !Ref EdgeZone - LaunchConfigurationName: !Ref LaunchConfigEdge + LaunchTemplate: + LaunchTemplateName: !Sub ${AWS::StackName}-AntMedia-LaunchTemplateEdge + Version: !GetAtt 'LaunchTemplateEdge.LatestVersionNumber' MinSize: !Ref AntMediaEdgeCapacity MaxSize: !Ref AntMediaEdgeCapacityMax DesiredCapacity: !Ref AntMediaEdgeCapacity @@ -621,78 +589,45 @@ Resources: - 'autoscaling:EC2_INSTANCE_LAUNCH_ERROR' - 'autoscaling:EC2_INSTANCE_TERMINATE' - 'autoscaling:EC2_INSTANCE_TERMINATE_ERROR' - LaunchConfigEdge: - Type: 'AWS::AutoScaling::LaunchConfiguration' - DependsOn: - - ApplicationLoadBalancer - Metadata: - Comment: Install a simple application - 'AWS::CloudFormation::Init': - configSets: - setup: - - "configure_cfn" - configure_cfn: - files: - /etc/cfn/cfn-hup.conf: - content: !Sub | - [main] - stack=${AWS::StackId} - region=${AWS::Region} - verbose=true - interval=5 - mode: "000400" - owner: root - group: root - /etc/cfn/hooks.d/cfn-auto-reloader.conf: - content: !Sub | - [cfn-auto-reloader-hook] - triggers=post.update - path=Resources.LaunchConfigEdge.Metadata.AWS::CloudFormation::Init - action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource LaunchConfigEdge --configsets setup --region ${AWS::Region} - mode: "000400" - owner: root - group: root - /lib/systemd/system/cfn-hup.service: - content: !Sub | - [Unit] - Description=cfn-hup daemon - - [Service] - Type=simple - ExecStart=/opt/aws/bin/cfn-hup - Restart=always - - [Install] - WantedBy=multi-user.target - mode: "000400" - owner: root - group: root - - Properties: - KeyName: !Ref KeyName - ImageId: !Ref AntMediaAmi - SecurityGroups: - - !Ref InstanceSecurityGroup - InstanceType: !Ref EdgeInstanceType - 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-init -v --stack ${AWS::StackName} --resource LaunchConfigEdge --configsets setup --region ${AWS::Region} - /opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource EdgeGroup --region ${AWS::Region} + + 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