我尝试连接的是Loadbalancer DNS名称到Route53.让我们看看例子.这是资源中模板的Loadbabancer:
"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"} ], } },
这是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", } }
只是把{"ElasticLoadBalancer":"DNSName"}放不起作用.有人可以建议或给我正确的方法来添加这个吗?
谢谢!
很可能你想获得DNSName
引用的LoadBalancer 的属性RestELB
.所以你需要一些Fn::GetAtt
像(未经测试的)
"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" } }
确保阅读有关AWS :: Route53 :: Recordset AliasTarget类型的CloudFormation文档:http ://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-aliastarget.html
这是为ELB创建别名目标时在CloudFormation中的外观:
"Route53LoadBalancerAlias" : { "Type" : "AWS::Route53::RecordSet", "Properties" : { "AliasTarget" : { "DNSName" : { "Fn::GetAtt" : [ "ELB", "DNSName" ]}, "EvaluateTargetHealth" : False, "HostedZoneId" : { "Fn::GetAtt" : [ "ELB", "CanonicalHostedZoneID" ]} },
对于负载均衡器,请使用负载均衡器的规范托管区域ID。对于Amazon S3,将托管区域ID用于存储桶的网站终端节点。对于CloudFront,请使用Z2FDTNDATAQYW2。有关其他服务的托管区域ID的列表,请参阅AWS区域和端点中的相关服务。
对于任何在2018年阅读此答案的人来说,我都在使用CanonicalHostedZoneNameID
而不是CanonicalHostedZoneID
"MyRecordSet": { "Type": "AWS::Route53::RecordSet", "Properties": { "HostedZoneName" : "example.com.", "Name": "abc.example.com.", "Type": "A", "AliasTarget": { "HostedZoneId" : {"Fn::GetAtt": ["MyELB", "CanonicalHostedZoneNameID"]}, "DNSName": {"Fn::GetAtt": ["MyELB", "DNSName"]}, "EvaluateTargetHealth": "false" } } }