当前位置:  开发笔记 > 编程语言 > 正文

如果可以使用AWS Cloudformation模板将Loadbalancers DNSname连接到Route53?

如何解决《如果可以使用AWSCloudformation模板将LoadbalancersDNSname连接到Route53?》经验,为你挑选了3个好方法。

我尝试连接的是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"}放不起作用.有人可以建议或给我正确的方法来添加这个吗?

谢谢!



1> Gonfva..:

很可能你想获得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"
      }
    }



2> 小智..:

确保阅读有关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区域和端点中的相关服务。



3> Aditya Talpa..:

对于任何在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"
        }
      }
    }


对于“ AWS :: ElasticLoadBalancingV2 :: LoadBalancer”,它仍然是“ CanonicalHostedZoneID”
推荐阅读
手机用户2502852037
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有