我正在使用python模块对流层来创建我的云形成模板。大部分内容都是完整的,但我似乎对如何使用RecordSets方法/函数为负载均衡器创建DNS条目感到困惑。此部分的输出应该如下所示:
"devdevopsdemoELBDNSARecord0": {
"Type": "AWS::Route53::RecordSetGroup",
"Properties": {
"HostedZoneName": "FOO.net.",
"Comment": "Alias targeted to devdevopsdemoELB ELB.",
"RecordSets": [
{
"Name": "devopsdemo.dev.FOO.net.",
"Type": "A",
"AliasTarget": {
"HostedZoneId": {
"Fn::GetAtt": [
"devdevopsdemoELB",
"CanonicalHostedZoneNameID"
]
},
"DNSName": {
"Fn::GetAtt": [
"devdevopsdemoELB",
"CanonicalHostedZoneName"
]
}
}
},
{
"Name": "devopsdemo-dev.FOO.net.",
"Type": "A",
"AliasTarget": {
"HostedZoneId": {
"Fn::GetAtt": [
"devdevopsdemoELB",
"CanonicalHostedZoneNameID"
]
},
"DNSName": {
"Fn::GetAtt": [
"devdevopsdemoELB",
"CanonicalHostedZoneName"
]
}
}
}
我开始时:
hostedzone = "FOO.net"
myRecordSet = RecordSetType("devdevopsdemoELBDNSARecord0")
myRecordSet.HostedZoneName=Join("", hostedzone, "."])
myRecordSet.Comment="Alias targeted to devdevopsdemoELB ELB."
但后来我不清楚如何输入RecordSets值。
我想我可以直接使用
myRecordSet.RecordSets =
然后把json放到位,但这似乎有点像滥用首先使用对流层的目的。
更新:输入json导致此错误
AttributeError:AWS :: Route53 :: RecordSet对象不支持属性RecordSets
myRecordSet.RecordSets = [
{
"Name": "devopsdemo.dev.FOO.net.",
"Type": "A",
"AliasTarget": {
"HostedZoneId": {
"Fn::GetAtt": [
"devdevopsdemoELB",
"CanonicalHostedZoneNameID"
]
},
"DNSName": {
"Fn::GetAtt": [
"devdevopsdemoELB",
"CanonicalHostedZoneName"
]
}
}
},
{
"Name": "devopsdemo-dev.FOO.net.",
"Type": "A",
"AliasTarget": {
"HostedZoneId": {
"Fn::GetAtt": [
"devdevopsdemoELB",
"CanonicalHostedZoneNameID"
]
},
"DNSName": {
"Fn::GetAtt": [
"devdevopsdemoELB",
"CanonicalHostedZoneName"
]
}
}
}
]
然后我尝试了这个:
myDNSRecord = t.add_resource(RecordSetGroup(
"devdevopsdemoELBDNSARecord0",
HostedZoneName=Join("", ["inpwrd.net", "."]),
Comment="DNS Entry to point to the ELB for devopsdemo",
RecordSets=[
RecordSet(
Name="devopsdemo.dev.inpwrd.net.",
Type="A",
AliasTarget=[HostedZoneId(GetAtt("devdevopsdemoELB", "CanonicalHostedZoneNameID")),
DNSName(GetAtt("devdevopsdemoELB", "CanonicalHostedZoneName"))],
),
RecordSet(
Name="devopsdemo-dev.inpwrd.net.",
Type="A",
AliasTarget=[HostedZoneId(GetAtt("devdevopsdemoELB", "CanonicalHostedZoneNameID")),
DNSName(GetAtt("devdevopsdemoELB", "CanonicalHostedZoneName"))],
),
],
)
)
找不到HostedZoneId
答案 0 :(得分:2)
AliasTarget采用AliasTarget助手类,所以你想这样做:
from troposphere import GetAtt, Join, Template
from troposphere.route53 import AliasTarget, RecordSetType, RecordSetGroup, RecordSet
t = Template()
myDNSRecord = t.add_resource(RecordSetGroup(
"devdevopsdemoELBDNSARecord0",
HostedZoneName=Join("", ["example.net", "."]),
Comment="DNS Entry to point to the ELB for devopsdemo",
RecordSets=[
RecordSet(
Name="devopsdemo.dev.example.net.",
Type="A",
AliasTarget=AliasTarget(
GetAtt("devdevopsdemoELB", "CanonicalHostedZoneNameID"),
GetAtt("devdevopsdemoELB", "CanonicalHostedZoneName"),
),
),
RecordSet(
Name="devopsdemo-dev.example.net.",
Type="A",
AliasTarget=AliasTarget(
GetAtt("devdevopsdemoELB", "CanonicalHostedZoneNameID"),
GetAtt("devdevopsdemoELB", "CanonicalHostedZoneName"),
),
),
],
)
)
print t.to_json()