如何在我的cloudformation脚本的输出部分中引用记录集名称?

时间:2015-02-02 14:52:48

标签: amazon-web-services amazon-cloudformation amazon-route53

我在我的cloudformation中创建了一些DNS条目。有一个参数传递到cfn脚本,这导致创建一个Route53条目,如hostname-test.example.com:

"Host" : {
  "Type" : "AWS::Route53::RecordSetGroup",
  "Properties" : {
      "HostedZoneName" : "example.com.",
      "RecordSets" : [
        {
          "Name" : { 
            "Fn::Join" : [ "-", [
                {"Ref" : "Hostname" },
                "test.example.com"
            ]]
          },
          "Type" : "A",
          "AliasTarget" : {
            "DNSName" : { "Fn::GetAtt" : [ "PublicWebLoadBalancer", "CanonicalHostedZoneName" ] },
            "HostedZoneId" : { "Fn::GetAtt" : [ "PublicWebLoadBalancer", "CanonicalHostedZoneNameID" ] }
          }
        }
      ]
  }
}

在我的输出中,我想从RecordSet中获取Name属性,但我不知道如何引用它。根据{{​​3}},不支持Route53对象。

这可能吗?

4 个答案:

答案 0 :(得分:3)

这个问题有点陈旧,但我刚遇到同样的问题。 您需要输出整个RecordSet,即:

"Outputs" : {
  "MyDNSRecord" : {
    "Description": "The DNS Record of ...",
    "Value" : { "Ref": "MyRecordSet" }
  }
}

(不直观地)输出您要查找的记录集名称的值。

答案 1 :(得分:1)

不是将RecordSet嵌入RecordSetGroup中,而是将其定义为单独的属性,使用与RecordSetGroup相同的HostedZoneName。

然后,您可以使用“Ref”获取Name属性的值。

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-recordset.html

答案 2 :(得分:1)

我有同样的问题,正在寻找一个明确的答案。

给出以下AWS :: Route53 :: RecordSet

rPublicReverseProxyNLBDnsRecord:
  Type: AWS::Route53::RecordSet
  Properties:
    HostedZoneName: !Ref pPublicHostedZoneName
    Comment:  !Sub 'DNS record for the ${AWS::StackName} ELB front door.'
    Name: !Sub '${pDeploymentType}.${pPublicHostedZoneName}'
    Type: CNAME
    TTL: '30'
    ResourceRecords:
      - !GetAtt rPublicReverseProxyNLB.DNSName

我能够使用以下输出部分代码输出所需的应用程序URL:

Outputs:

  ApplicationURL:
    Description: 'The public URL for the application'
    Value: !Sub 'https://${rPublicReverseProxyNLBDnsRecord}/'

答案 3 :(得分:-1)

我接下来尝试 RecordSet 的建议。

但是你的名字"是确定性的。如果堆栈完成,输出您已经拥有的内容将永远不会与您想要的行为不同:

          { 
            "Fn::Join" : [ "-", [
                {"Ref" : "Hostname" },
                "test.example.com"
            ]]
          }

如果这是OOP,我会说在没有机会暗中测试该功能的情况下发起争论是完全错误的。