Lakshay Bansal
Lakshay Bansal

Reputation: 397

Is there a way to fetch HostedZoneId from DNS name in CFT?

In CloudFormation Template, can we fetch HostedZoneId from DNS name? One way is we check the resource and look for the HostedZoneId and insert it. Can we also use GetAtt or any other function to get the id.

I want to do something like this on HostedZoneId but this is incorrect. Is there any other way to do this?

Parameter:
  VPCEDNS:
  Description: VPCe DNS target 
  Type: String

Resources:
  PrimaryRecord:
    Type: AWS::Route53::RecordSet
    Properties: 
      AliasTarget: 
        HostedZoneId: !GetAtt (!Ref "VPCEDNS").HostedZoneId
        DNSName: !Ref "VPCEDNS"
        EvaluateTargetHealth: true
      Failover: PRIMARY
      HostedZoneName: example.com
      Name: service.example.com
      Type: A

Upvotes: 0

Views: 324

Answers (1)

Marcin
Marcin

Reputation: 238111

Sadly, in plain CFN there is no such way. If you really would need such functionality, you would have to use custom resource.

The resource would be in the form of a lambda function, which would take your DNS name as input parameter. Then using AWS SDK (e.g. boto3), it would find and match the corresponding hosted zone, and return its ID into your CFN stack for further use.

Upvotes: 1

Related Questions