Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify HostedZone NameServers as CloudFormation Outputs

I am creating a CFN stack for a number of domains. The domain are not with the AWS registry, but a third-party one.

I want to have the list of nameservers from the SOA as part of the stack Outputs. However, as they aren't returned as a string but, according to the docs, a "set", I can't figure out how to extract and return them.

Details:

According to the docs for AWS::Route53::HostedZone, you can obtain the list of nameservers with

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.

So, I tried to do:

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

but that gives:

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

When I only output the zone ref, it works just fine and get the Z... string for the zone.

I've tried various other tricks and approaches, mostly with various intrinsic functions such as !Split, !Select, etc. Nowhere can I seem to find what this "set" is: a list? a comma-separated string? (in which case !Split should work)

I could retrieve the nameservers via the describe function of Route53 after the stack is created, but my feeling is that I'm missing something totally obvious so don't want to add that extra step.

like image 443
Marakai Avatar asked Mar 19 '19 05:03

Marakai


People also ask

How do you reference output in CloudFormation?

Listing exported output values Amazon CloudFormation shows the names and values of the exported outputs for the current region and the stack from which the outputs are exported. To reference an exported output value in a stack's template, use the export name and the Fn::ImportValue function.

What are outputs in CloudFormation?

The optional Outputs section declares output values that you can import into other stacks (to create cross-stack references), return in response (to describe stack calls), or view on the AWS CloudFormation console. For example, you can output the S3 bucket name for a stack to make the bucket easier to find.

How do I Export Route 53 hosted zone records?

Sign in to the AWS Management Console and open the Route 53 console at https://console.aws.amazon.com/route53/ . Sign in with the account credentials for the account that created the old hosted zone. In the navigation pane, choose Hosted zones. Choose the name of the old hosted zone.


1 Answers

The set of nameservers is an array of strings. In order to output it you need to use !Join like this:

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

You should see the following Outputs: Console screenshot of CloudFormation Outputs

like image 157
jogold Avatar answered Sep 28 '22 16:09

jogold