Search code examples
amazon-web-servicesaws-cloudformationamazon-route53

Using Join, Select, and Split with Private IP value on Cloudformation


I am getting a bug when trying to compose a reverse zone entry dns in Cloudformation.

This is my entry:

EC2DNSReverseZone:
Type: AWS::Route53::RecordSet
Properties:
  HostedZoneId: !Ref ReverseHostedZoneId
  Name:
    - !Join [ '', [ !Select [3, !Split [ ".", !GetAtt LinuxEC2Instance.PrivateIp ] ], .xxx.xxx.xx.in-addr.arpa  ] ]
  Type: PTR
  TTL: '86400'
  ResourceRecords:
    - xxxxxxxx

When deploying the Cloudformation entry, I receive the following error:

Value of property Name must be of type String

I assume that this has to do with the fact that LinuxEC2Instance.PrivateIp is a number and it is not valid to Split a number. But this is just a guess. I am a bit at a loss what I am doing wrong here. LinuxEC2Instance.PrivateIp is an ip address like 10.104.209.113 and I only need the last part so I need 113 from that number, that is why I am using split here.

What do I need to do to fix this error?


Solution

  • I assume that this has to do with the fact that LinuxEC2Instance.PrivateIp is a number and it is not valid to Split a number.

    No its not. It means that your Name is List, as you put - in it. It must be plain String, so it should be (no -):

      Name:
        !Join [ '', [ !Select [0, !Split [ ".", !GetAtt LinuxEC2Instance.PrivateIp ] ], .xxx.xxx.xx.in-addr.arpa  ] ]
    

    The Join can have other mistakes, but I only concentrate on your current error message.