Skip to content
Advertisement

Use Route53 template in cloudformation with Cloudfront

"DNS": {
           "Type": "AWS::Route53::RecordSet",
           "Properties": {
             "HostedZoneId" : "Z058101PST6709",
             "RecordSets" : [{
                    "Name" : {
                        "Ref": "AlternateDomainNames"
                    },
                    "Type" : "CNAME",
                    "TTL" : "900",
                    "ResourceRecords" : {
                        "Ref": "myDistribution"
                    },
                    "Weight" : "140"
                }]
           }
        }

Hi Team, I am going to create a route53 record with cloudfront please find the cloud-formation code and in which I am getting an error while create a stack. Basically I want to create a CNAME record by using cloudfront domain name. Please help me out in this.

Advertisement

Answer

You can use the below template

"DNS": {
    "Type": "AWS::Route53::RecordSet",
    "Properties": {
        "HostedZoneId": "Z058101PST6709",
        "Name": {
            "Ref": "AlternateDomainNames"
        },
        "ResourceRecords": [{ "Fn::GetAtt": ["myDistribution", "DomainName"] }],
        "TTL": "900",
        "Type": "CNAME"
    }
}

I should raise as you’re using Route 53 you should take advantage of using Alias records instead of CNAME records for your CloudFront Distribution.

This could be done via the below.

{
    "Type": "AWS::Route53::RecordSetGroup",
    "Properties": {
        "HostedZoneId": "Z058101PST6709",
        "RecordSets": [{
            "Name": {
                "Ref": "AlternateDomainNames"
            },
            "Type": "A",
            "AliasTarget": {
                "HostedZoneId": "Z2FDTNDATAQYW2",
                "DNSName": { "Fn::GetAtt": ["myDistribution", "DomainName"] }
            }
        }]
    }
}
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement