将HostedZone名称服务器指定为CloudFormation输出

时间:2019-03-19 05:04:00

标签: amazon-cloudformation amazon-route53

我正在为多个域创建CFN堆栈。该域不在AWS注册表中,而是第三方注册表。

我想将SOA中的名称服务器列表作为堆栈输出的一部分。但是,由于它们不是以字符串形式返回,而是根据文档,是一个“集合”,因此我无法弄清楚如何提取并返回它们。

详细信息:

根据AWS::Route53::HostedZone的文档,您可以使用

获取名称服务器列表
  

返回值

     

[...]

     

Fn :: GetAtt

     

Fn :: GetAtt返回此类型的指定属性的值。的   以下是可用的属性和示例返回值。

     

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.

当我只输出区域ref时,它可以正常工作并获取区域的Z ...字符串。

我尝试了其他各种技巧和方法,其中大多数都使用了各种内在功能,例如!Split!Select等。我似乎在哪里都找不到这个“集合”是什么:列表?逗号分隔的字符串? (在这种情况下,!Split应该有效)

创建堆栈后,我可以通过Route53的describe函数检索名称服务器,但是我的感觉是我遗漏了一些显而易见的东西,所以不想添加额外的步骤。

1 个答案:

答案 0 :(得分:2)

一组名称服务器是一个字符串数组。为了输出它,您需要像这样使用!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

您应该看到以下输出: Console screenshot of CloudFormation Outputs