将 HostedZone NameServers 指定为 CloudFormation 输出

Mar*_*kai 5 aws-cloudformation amazon-route53

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

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

细节:

根据 docs for AWS::Route53::HostedZone,您可以获得名称服务器列表

返回值

[...]

Fn::GetAtt

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

名称服务器

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.
Run Code Online (Sandbox Code Playgroud)

所以,我试图这样做:

Resources:
  MyZone:
    Type: 'AWS::Route53::HostedZone'
    Properties:
      Name: my.domain.    
...
Outputs:
  MyZone:
    Value: !Ref MyZone
  MyZoneServers:
    Value: !GetAtt MyZone.NameServers
Run Code Online (Sandbox Code Playgroud)

但这给出了:

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

当我只输出区域引用时,它工作得很好并获取区域的 Z... 字符串。

我已经试过各种其他的技巧和方法,主要有各种内在的功能,如!Split!Select等无处可我似乎找到什么这个“集”是:一个列表?逗号分隔的字符串?(在这种情况下!Split应该工作)

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

jog*_*old 9

名称服务器集是一个字符串数组。为了输出它,您需要!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
Run Code Online (Sandbox Code Playgroud)

您应该看到以下输出: CloudFormation 输出的控制台屏幕截图