user4093955
user4093955

Reputation:

How can I get the VPC Endpoint DNS name for Route53 in CloudFormation?

In a CloudFormation template I want to create both a VPC Endpoint and a Route53 Record pointing to it.

This is the record definition:

  Domain:
    Type: AWS::Route53::RecordSet
    Properties:
      AliasTarget:
        DNSName: ---- NEED THIS VALUE ----
        HostedZoneId: !Ref HostedZoneId
      HostedZoneId: !Ref HostedZoneId
      Name: !Ref DomainName
      Type: A

According to the docs, the VPC Endpoint has an output DnsEntries which returns a list like ["Z1HUB23UULQXV:vpce-01abc23456de78f9g-12abccd3.ec2.us-east-1.vpce.amazonaws.com", "Z1HUB23UULQXV:vpce-01abc23456de78f9g-12abccd3-us-east-1a.ec2.us-east-1.vpce.amazonaws.com", "Z1C12344VYDITB0:ec2.us-east-1.amazonaws.com"].

In that example, I would need for the DNSName the value vpce-01abc23456de78f9g-12abccd3.ec2.us-east-1.vpce.amazonaws.com, that is, the first item in the list without the Hosted Zone ID.

But I don't know how to fetch that within a CloudFormation template.

I was trying the following: !Select ['1', !Split [':', [!Select ['0', !GetAtt VPCEndpoint.DnsEntries]]]], but I'm getting the following error: "[cfn-lint] E1018: Split has to be of type string or valid function for Resources/Domain/Properties/AliasTarget/DNSName/Fn::Select/1/Fn::Split"

Upvotes: 2

Views: 1684

Answers (1)

user4093955
user4093955

Reputation:

Found the issue.

The second argument of Split was wrong. It has to be a String, not a list.

This is the correct one:

!Select ['1', !Split [':', !Select ['0', !GetAtt VPCEndpoint.DnsEntries]]]

Notice there is no [ between , and !Select.

Upvotes: 3

Related Questions