将HostedZone NameServers指定为CloudFormation输出

问题描述 投票:0回答:1

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

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

细节:

根据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.

所以,我试着这样做:

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函数检索名称服务器,但我的感觉是我遗漏了一些非常明显的东西,所以不想添加额外的步骤。

amazon-cloudformation amazon-route53
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.