Stack Exchange
Getting error while creating ELB in cloudformation
AWSTemplateFormatVersion: 2010-09-09
Resources:
  MyLoadBalancer:
    Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer'
    Properties:
      IpAddressType: ipv4
      AvailabilityZones:
        - ap-southeast-1
      Name: mytestingELB
      Scheme: internet-facing
      Type: application
      SecurityGroups:
        - !Ref sg-**********
      Subnets:
        - !Ref subnet-******
        - !Ref subnet-*******
      Metadata:
        'AWS::CloudFormation::Designer':
          id: 3f17841f-7296-4aeb-a464-94dbbf6542fd
      'AWS::ElasticLoadBalancingV2::TargetGroup':
        Properties:
          HealthCheckIntervalSeconds: '30'
          HealthCheckPath: /
          HealthCheckProtocol: HTTP
          HealthCheckTimeoutSeconds: '5'
          HealthyThresholdCount: '5'
          Matcher:
            HttpCode: '200'
          Name: testingtargetgroup
          Port: '80'
          Protocol: HTTP
          TargetType: instance
          UnhealthyThresholdCount: '2'
          VpcId: !Ref vpc-******

Getting error Template is not valid: Template format error: Unresolved resource dependencies [subnet-, sg-, subnet-, vpc-*] in the Resources block of the template
PLease hel me to add

If vpc-******, subnet-******, sg-********** are actual IDs of your existing VPC, subnets, and security group, then you do not need !Ref to reference them.
Just provide them without !Ref, e.g.
SecurityGroups:
  - sg-**********
Subnets:
  - subnet-******
  - subnet-*******

VpcId: vpc-******

New template version:
AWSTemplateFormatVersion: 2010-09-09
Resources:
  MyLoadBalancer:
    Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer'
    Properties:
      IpAddressType: ipv4
      Name: mytestingELB
      Scheme: internet-facing
      Type: application
      SecurityGroups:
        - !Ref sg-**********
      Subnets:
        - !Ref subnet-******
        - !Ref subnet-*******

  MyTargetGroup
      'AWS::ElasticLoadBalancingV2::TargetGroup':
        Properties:
          HealthCheckIntervalSeconds: '30'
          HealthCheckPath: /
          HealthCheckProtocol: HTTP
          HealthCheckTimeoutSeconds: '5'
          HealthyThresholdCount: '5'
          Matcher:
            HttpCode: '200'
          Name: testingtargetgroup
          Port: '80'
          Protocol: HTTP
          TargetType: instance
          UnhealthyThresholdCount: '2'
          VpcId: !Ref vpc-******

MyTargetGroup was added and AvailabilityZones and Metadata removed.

Thanks @Marcin
Now I got two errors while creating this
Encountered unsupported property AvailabilityZones
The following resource(s) failed to create: [MyLoadBalancer]. . Rollback requested by user

@shubhamkamboj The template has many other issues. It will be difficult to address all of them at once. Maybe check the source of the template. It could be copped  incorrectly or modified. I will ammend an answer.

It showing a template error.
Actually my aim is to create auto-scaling with ELB. So if you have any template for creating auto-scaling. can you please send this to me. I am new in cloud-formation.

@shubhamkamboj No problem. Hope it will work out. If you will have future issues, please feel free to make new questions.

Hi Marcin,
I have tried many possibilities but not able to crate ELB. So I really appreciate if you will provide me the template. or fix my template issues.

@shubhamkamboj I think the best would be to create new question with updated template and new error messages. It difficult to know now, what is the current state of your template and what errors you are having now. Btw,  if you would like to accept the question, you can click 'tick' next to it, if it was helpful.
