title: Autoscaling using cloudformation
body: <p>I have come up with an template but it shows an error <code>Template format error: [/Resources/MyServerGroup] resource definition is malformed</code> I have tried solving it but unable to. Please do review the template also I am new to this there might be some mistakes. I have taken help from this link <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-autoscaling.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-autoscaling.html</a></p>
  <pre><code>---
  AWSTemplateFormatVersion: 2010-09-09
  Parameters:
    SourceStackName:
      Description: &quot;Source stack name&quot;
      Type: String
      AllowedPattern: &quot;^[a-zA-Z][-a-zA-Z0-9]*$&quot;
      Default: &quot;noob-vpc&quot;
  Resources:
    ec2instance:
      Type: AWS::AutoScaling::LaunchConfiguration
      Properties:
        AvailabilityZone: us-east-2a
        BlockDeviceMappings:
          - DeviceName: /dev/xvda
            Ebs:
              DeleteOnTermination: &quot;true&quot;
              VolumeSize: &quot;8&quot;
              VolumeType: gp2
        ImageId: ami-0bdcc6c05dec346bf
        InstanceType: t2.micro
        KeyName: sg-webserver
        NetworkInterfaces:
          - Description: Primary network interface
            DeviceIndex: 0
            SubnetId:
              Fn::ImportValue:
                Fn::Sub: &quot;${SourceStackName}-PublicSubnet&quot;
            GroupSet:
              - !Ref webserver
   
    webserver:
      Type: AWS::EC2::SecurityGroup
      Properties:
        GroupName: gn-webserver
        SecurityGroupIngress:
          - IpProtocol: tcp
            FromPort: 22
            ToPort: 22
            CidrIp: 0.0.0.0/0
            Description: For traffic from Internet
          - IpProtocol: tcp
            FromPort: 80
            ToPort: 80
            CidrIp: 0.0.0.0/0
            Description: For traffic from Internet
        GroupDescription: Security Group for demo server
        VpcId:
          Fn::ImportValue:
            Fn::Sub: &quot;${SourceStackName}-VpcID&quot;
    MyServerGroup:
    Type: AWS::AutoScaling::AutoScalingGroup
    Properties:
      AvailabilityZones: us-east-2
      LaunchConfigurationName:
        Ref: ec2instance
      MinSize: '2'
      MaxSize: '3'
      # LoadBalancerNames:
      # - Ref: LB
    MyAsGroupWithNotification:
    Type: AWS::AutoScaling::AutoScalingGroup
    Properties:
      AvailabilityZones: us-east-2
      LaunchConfigurationName:
        Ref: myLCOne
      MinSize: '0'
      MaxSize: '2'
      DesiredCapacity: '1'
      NotificationConfigurations:
      - TopicARN:
          Ref: topic1
        NotificationTypes:
        - autoscaling:EC2_INSTANCE_LAUNCH
        - autoscaling:EC2_INSTANCE_LAUNCH_ERROR
        - autoscaling:EC2_INSTANCE_TERMINATE
        - autoscaling:EC2_INSTANCE_TERMINATE_ERROR
  </code></pre>
  <p>Secondly Please check if I am not missing anything. I have read the documentation and come up with this template. I have another template VPC inn which I have created the subnets and imported their values into this template</p>
  <p>VPC:</p>
  <pre><code>---
  AWSTemplateFormatVersion: 2010-09-09
  Resources:
    VPC:
      Type: AWS::EC2::VPC
      Properties:
        CidrBlock: 11.0.0.0/16
        EnableDnsSupport: true
        EnableDnsHostnames: true
        InstanceTenancy: default
    InternetGateway:
      Type: AWS::EC2::InternetGateway
    VPCGatewayAttachment:
      Type: AWS::EC2::VPCGatewayAttachment
      Properties:
        VpcId: !Ref VPC
        InternetGatewayId: !Ref InternetGateway
    SubnetA:
      Type: AWS::EC2::Subnet
      Properties:
        AvailabilityZone: us-east-2a
        VpcId: !Ref VPC
        CidrBlock: 11.0.0.0/24
        MapPublicIpOnLaunch: true
    SubnetB:
      Type: AWS::EC2::Subnet
      Properties:
        AvailabilityZone: us-east-2b
        VpcId: !Ref VPC
        CidrBlock: 11.0.1.0/24
        MapPublicIpOnLaunch: true
    SubnetC:
      Type: AWS::EC2::Subnet
      Properties:
        AvailabilityZone: us-east-2b
        VpcId: !Ref VPC
        CidrBlock: 11.0.2.0/24
        MapPublicIpOnLaunch: false
    SubnetD:
      Type: AWS::EC2::Subnet
      Properties:
        AvailabilityZone: us-east-2b
        VpcId: !Ref VPC
        CidrBlock: 11.0.3.0/24
        MapPublicIpOnLaunch: false
    RouteTable:
      Type: AWS::EC2::RouteTable
      Properties:
        VpcId: !Ref VPC
    RouteTable2:
      Type: AWS::EC2::RouteTable
      Properties:
        VpcId: !Ref VPC
    InternetRoute:
      Type: AWS::EC2::Route
      DependsOn: VPCGatewayAttachment
      Properties:
        DestinationCidrBlock: 0.0.0.0/0
        GatewayId: !Ref InternetGateway
        RouteTableId: !Ref RouteTable
    SubnetARouteTableAssociation:
      Type: AWS::EC2::SubnetRouteTableAssociation
      Properties:
        RouteTableId: !Ref RouteTable
        SubnetId: !Ref SubnetA
    SubnetBRouteTableAssociation:
      Type: AWS::EC2::SubnetRouteTableAssociation
      Properties:
        RouteTableId: !Ref RouteTable
        SubnetId: !Ref SubnetB
    SubnetCRouteTableAssociation:
      Type: AWS::EC2::SubnetRouteTableAssociation
      Properties:
        RouteTableId: !Ref RouteTable2
        SubnetId: !Ref SubnetC
  
    SubnetDRouteTableAssociation:
      Type: AWS::EC2::SubnetRouteTableAssociation
      Properties:
        RouteTableId: !Ref RouteTable2
        SubnetId: !Ref SubnetD
    SecurityGroup:
      Type: AWS::EC2::SecurityGroup
      Properties:
        GroupName: &quot;Internet Group&quot;
        GroupDescription: &quot;SSH traffic in, all traffic out.&quot;
        VpcId: !Ref VPC
        SecurityGroupIngress:
          - IpProtocol: tcp
            FromPort: &quot;22&quot;
            ToPort: &quot;22&quot;
            CidrIp: 0.0.0.0/0
        SecurityGroupEgress:
          - IpProtocol: -1
            CidrIp: 0.0.0.0/0
  Outputs:
    vpcID:
      Description: VPC id
      Value: !Ref VPC
      Export:
        Name:
          Fn::Sub: &quot;${AWS::StackName}-VpcID&quot;
    SubnetA:
      Description: public subnet
      Value: !Ref SubnetA
      Export:
        Name:
          Fn::Sub: &quot;${AWS::StackName}-SubnetA&quot;
    SubnetB:
      Description: public subnet 2
      Value: !Ref SubnetB
      Export:
        Name:
          Fn::Sub: &quot;${AWS::StackName}-SubnetB&quot;
    SubnetC:
      Description: priavte subnet
      Value: !Ref SubnetC
      Export:
        Name:
          Fn::Sub: &quot;${AWS::StackName}-SubnetC&quot;
    SubnetD:
      Description: private subnet 2
      Value: !Ref SubnetD
      Export:
        Name:
          Fn::Sub: &quot;${AWS::StackName}-SubnetD&quot;
  </code></pre>