将托管区域名称服务器指定为CloudFormation输出

11

我正在为多个域名创建一个CFN堆栈。这些域名不在AWS注册表中,而是由第三方提供。

我希望将SOA的名称服务器列表作为堆栈输出之一。但是,由于它们并不返回为字符串,根据文档,它们会作为“集合”,我无法想出如何提取和返回它们。

详细信息:

根据 AWS::Route53::HostedZone 的文档,您可以使用以下命令获取名称服务器列表

Return Values

[...]

Fn::GetAtt

Fn::GetAtt returns a value for a specified attribute of this type. The following are the available attributes and sample return values.

NameServers

Returns the **set** of name servers for the specific hosted zone. For example: ns1.example.com.

This attribute is not supported for private hosted zones.

所以,我尝试做:

Resources:
  MyZone:
    Type: 'AWS::Route53::HostedZone'
    Properties:
      Name: my.domain.    
...
Outputs:
  MyZone:
    Value: !Ref MyZone
  MyZoneServers:
    Value: !GetAtt MyZone.NameServers

但这会得到:

An error occurred (ValidationError) when calling the UpdateStack operation: Template format error: The Value field of every Outputs member must evaluate to a String.

当我只输出区域引用时,可以正常工作并获取区域的字符串。

我尝试了各种其他技巧和方法,主要使用各种内置函数,例如!Split!Select等。我似乎找不到这个“set”是什么:一个列表吗?逗号分隔的字符串?(在这种情况下,!Split应该工作)

在堆栈创建后,我可以通过Route53的描述功能检索名称服务器,但我感觉自己漏掉了一些非常明显的东西,所以不想添加额外的步骤。

1个回答

17

域名服务器集合是一个字符串数组。要输出它,您需要像这样使用!Join

Resources:
  MyZone:
    Type: 'AWS::Route53::HostedZone'
    Properties:
      Name: my.domain.    
...
Outputs:
  MyZone:
    Value: !Ref MyZone
  MyZoneServers:
    Value: !Join [',', !GetAtt MyZone.NameServers] # or any other delimiter that suits you

您应该看到以下输出内容: CloudFormation Outputs 的控制台截图


哦,亲爱的,我一定是在深夜工作,因为我发誓除了其他一些随机的事情,我也尝试过这个!回到绘图板上,多睡一会儿,如果它起作用,你就得到了积分。 :D - Marakai
CDK(Python)版本的代码为:aws_cdk.Fn.join(",",MyZone.hosted_zone_name_servers) - Efren

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接