<p>we have Cloudformation template through which we deploy the infra resources for our product. and below are the AWS component which are creating through CF templates:
1. Networking Components. Like VPC, Subnets, Security groups etc.
2. IAM roles and policies.
3. EMR
4. EKS
5. MSK
6. RDS
7. Elasticache</p>

<p>also in our Cloudformation templates we have few custom resources like "Custom::KubeManifest". through which we are deploying the objects in AWS EKS cluster. one of our kubernetes object is "Service" object. which creates a service endpoints for internal services so that requests from public network can reach to our kubernetes cluster.</p>

<p>we wanted to check if we can reference the existing ELB DNS names in Cloudformation templates so that we can show the ELB DnsName in as Output.</p>

<p>for Example, when we call the "Custom::KubeManifest" resources as below template:</p>

<pre><code>  ServiceDeployment:
    Type: "Custom::KubeManifest"
    Version: '1.0'
    Properties:
      ServiceToken: !Ref KubeManifestLambdaArn
      KubeConfigPath: !Sub "s3://${KubeConfigS3Bucket}/${KubeConfigS3Key}"
      KubeConfigKmsContext: !Ref KmsContext
      Manifest:
        apiVersion: v1
        kind: Service
        metadata:
          name: test
          labels:
            app: client
            tier: master
        spec:
          selector:
            app: client
            tier: master
          ports:
          - name: client-api
            port: 9877
            protocol: TCP
          - name: client-snapshots
            port: 9878
            protocol: TCP
          - name: client-support
            port: 9881
            protocol: TCP
  UiDeployment:
    Type: "Custom::KubeManifest"
    Version: '1.0'
    Properties:
      ServiceToken: !Ref KubeManifestLambdaArn
      KubeConfigPath: !Sub "s3://${KubeConfigS3Bucket}/${KubeConfigS3Key}"
      KubeConfigKmsContext: !Ref KmsContext
      Manifest:
        apiVersion: v1
        kind: Service
        metadata:
          name: client-ui
          annotations:
            service.beta.kubernetes.io/aws-load-balancer-internal: 0.0.0.0/0
            service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: '*'
            service.beta.kubernetes.io/aws-load-balancer-type: nlb
            service.beta.kubernetes.io/aws-load-balancer-backend-protocol: 'tcp'
            service.beta.kubernetes.io/aws-load-balancer-ssl-ports: "tcp"
            service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout: "60"
          labels:
            app: client
            tier: master
        spec:
          type: LoadBalancer
          selector:
            app: client
            tier: master
          ports:
          - name: client-ui
            port: 80
            protocol: TCP
            targetPort: 8800
          - name: client-ui-https
            port: 443
            protocol: TCP
            targetPort: 8800
</code></pre>

<p>it creates a ELB in AWS account and maps it with the Service endpoints in the EKS cluster. now we want to know that if by any functions we can reference the newly created ELB DnsNames and show it as Output.</p>

<p>This is my YAML example</p>

<pre><code>Resources:
  LoadBalancer:
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    Properties:
      Name: !Ref EnvironmentName
      Subnets: !Ref Subnets
      SecurityGroups:
        - !Ref SecurityGroup
      Tags:
        - Key: Name
          Value: !Ref EnvironmentName

  LoadBalancerListener:
    Type: AWS::ElasticLoadBalancingV2::Listener
    Properties:
      LoadBalancerArn: !Ref LoadBalancer
      Port: 80
      Protocol: HTTP
      DefaultActions:
        - Type: forward
          TargetGroupArn: !Ref DefaultTargetGroup
</code></pre>

<p>Both <code>LoadBalancer</code> and <code>LoadBAlanceListener</code>  must be included. Then you must add outputs which  declare values that you want available to a describe stacks API call.</p>

<pre><code>Outputs:
  LoadBalancer:
    Description: A reference to the Application Load Balancer
    Value: !Ref LoadBalancer

  LoadBalancerUrl:
    Description: The URL of the ALB
    Value: !GetAtt LoadBalancer.DNSName

  Listener:
    Description: A reference to a port 80 listener
    Value: !Ref LoadBalancerListener
</code></pre>
