AWS CDK Python:尝试使用查找区域创建 A 记录时出错
AWS CDK Python: Error when trying to create A Record using zone from lookup
使用 Python3.8,CDK 2.19.0
我想针对我的 AWS 账户中已有的托管区域创建 A 记录。
我正在做以下事情:
hosted_zone = route53.HostedZone.from_hosted_zone_attributes(self, "zone",
zone_name="my.awesome.zone.",
hosted_zone_id="ABC12345DEFGHI"
)
route53.ARecord(self, "app_record_set",
target=self.lb.load_balancer_dns_name, # this is declared above, and works fine.
zone=hosted_zone,
record_name="test-cdk.my.awesome.zone"
)
在我的app.py
里面我有:
env_EU = cdk.Environment(account="12345678901112", region="eu-west-1")
app = cdk.App()
create_a_record = DomianName(app, "DomianName", env=env_EU)
当我 运行 cdk synth
我得到以下错误:
➜ cdk synth
jsii.errors.JavaScriptError:
Error: Expected object reference, got "${Token[TOKEN.303]}"
File ".../.venv/lib/python3.8/site-packages/jsii/_kernel/providers/process.py", line 326, in send
...(full traceback)
Subprocess exited with error 1
我试过 from_lookup
(而不是 from_hosted_zone_attributes
、Python3.9/Node 17/12/16(以防万一)但没有任何帮助。我明白了每次都出现同样的错误。
如果我注释掉 A Record 创建,则合成器会按预期完成。
cdk.context.json
也缓存了正确的托管区域,但仅当我注释掉 A 记录创建时才会发生。
ARecord
目标需要一种类型 RecordTarget. You are passing a string
(token). Use a LoadBalancerTarget:
import aws_cdk.aws_elasticloadbalancingv2 as elbv2
# zone: route53.HostedZone
# lb: elbv2.ApplicationLoadBalancer
route53.ARecord(self, "AliasRecord",
zone=zone,
target=route53.RecordTarget.from_alias(targets.LoadBalancerTarget(lb))
)
使用 Python3.8,CDK 2.19.0
我想针对我的 AWS 账户中已有的托管区域创建 A 记录。
我正在做以下事情:
hosted_zone = route53.HostedZone.from_hosted_zone_attributes(self, "zone",
zone_name="my.awesome.zone.",
hosted_zone_id="ABC12345DEFGHI"
)
route53.ARecord(self, "app_record_set",
target=self.lb.load_balancer_dns_name, # this is declared above, and works fine.
zone=hosted_zone,
record_name="test-cdk.my.awesome.zone"
)
在我的app.py
里面我有:
env_EU = cdk.Environment(account="12345678901112", region="eu-west-1")
app = cdk.App()
create_a_record = DomianName(app, "DomianName", env=env_EU)
当我 运行 cdk synth
我得到以下错误:
➜ cdk synth
jsii.errors.JavaScriptError:
Error: Expected object reference, got "${Token[TOKEN.303]}"
File ".../.venv/lib/python3.8/site-packages/jsii/_kernel/providers/process.py", line 326, in send
...(full traceback)
Subprocess exited with error 1
我试过 from_lookup
(而不是 from_hosted_zone_attributes
、Python3.9/Node 17/12/16(以防万一)但没有任何帮助。我明白了每次都出现同样的错误。
如果我注释掉 A Record 创建,则合成器会按预期完成。
cdk.context.json
也缓存了正确的托管区域,但仅当我注释掉 A 记录创建时才会发生。
ARecord
目标需要一种类型 RecordTarget. You are passing a string
(token). Use a LoadBalancerTarget:
import aws_cdk.aws_elasticloadbalancingv2 as elbv2
# zone: route53.HostedZone
# lb: elbv2.ApplicationLoadBalancer
route53.ARecord(self, "AliasRecord",
zone=zone,
target=route53.RecordTarget.from_alias(targets.LoadBalancerTarget(lb))
)