muzafarow muzafarow - 4 months ago 25
JSON Question

If it possible connect Loadbalancers DNSname to Route53 using AWS Cloudformation template?

What I trying to connect is Loadbalancer DNS name to to Route53.
Lets look on example.
Here is Loadbabancer from template in Resource:

"RestELB" : {
"Type" : "AWS::ElasticLoadBalancing::LoadBalancer",
"DependsOn": "AttachGateway",
"Properties": {
"LoadBalancerName": {"Fn::Join": ["",["Rest-ELB-", {"Ref": "VPC"}]]},
"CrossZone" : "true",
"Subnets": [{ "Ref": "PublicSubnet1" },{ "Ref": "PublicSubnet2" }],
"Listeners" : [
{"LoadBalancerPort" : "80", "InstancePort" : "80","Protocol" : "HTTP"},
{"LoadBalancerPort" : "6060", "InstancePort" : "6060","Protocol" : "HTTP"}
],
}
},


And Here is Route53:

"ApiRecordSet" : {
"Type" : "AWS::Route53::RecordSet",
"Properties" : {
"AliasTarget" :{
"DNSName" : [
{"Fn::Join": ["", [{"ElasticLoadBalancer": "DNSName"},"."]]}
],
"EvaluateTargetHealth" : "Boolean",
"HostedZoneId" : "String"
},
"HostedZoneName" : "example.net.",
"Comment" : "A records for my frontends.",
"Name" : "api.example.net.",
"Type" : "A",
"TTL" : "900",
}
}


Just to put {"ElasticLoadBalancer": "DNSName"} didn't work. Can someone to suggest or give me correct way to add this?

Thanks!

Answer

Most likely you want to get the attribute DNSName for the LoadBalancer whose reference is RestELB. So you will need something with Fn::GetAtt like (untested)

   "ApiRecordSet" : {
      "Type" : "AWS::Route53::RecordSet",
      "Properties" : {
        "AliasTarget" :{
          "DNSName" : { "Fn::GetAtt" : [ "RestELB", "DNSName" ]},
          "EvaluateTargetHealth" : "Boolean",
          "HostedZoneId" : "String"
        },
        "HostedZoneName" : "example.net.",
        "Comment" : "A records for my frontends.",
        "Name" : "api.example.net.",
        "Type" : "A"
      }
    }
Comments