1
votes

EDIT Solved, the solution is in the comments.

I'm trying to create a record set in AWS Route53 that targets an alias CloudFront distribution.

At the moment, I'm creating a new hosted zone with the desired domain (works fine).

Afterward, I'm taking the HostedZoneId from the response and trying to create a recordset that points to a CloudFront Distribution that has this domain in his CNAMEs. (If I only create the hosted zone using the API and then trying to create the record set manually it works fine and I can see the CDN Alias on the list).

I'm following this example from AWS Documentation -

var response = client.ChangeResourceRecordSets(new ChangeResourceRecordSetsRequest 
{
    ChangeBatch = new ChangeBatch {
        Changes = new List<change> {
            new Change {
                Action = "CREATE",
                ResourceRecordSet = new ResourceRecordSet {
                    AliasTarget = new AliasTarget {
                        DNSName = "d123rk29d0stfj.cloudfront.net",
                        EvaluateTargetHealth = false,
                        HostedZoneId = "Z2FDTNDATAQYW2" // Different Hosted Zone?
                    },
                    Name = "example.com",
                    Type = "A"
                }
            }
        },
        Comment = "CloudFront distribution for example.com"
    },
    HostedZoneId = "Z3M3LMPEXAMPLE" // Different Hosted Zone?
});

Why is the Alias Target HostedZoneId property and the outer HostedZoneId aren't the same??? shouldn't they both be the Id of the hosted zone created for the desired domain?

The error I receive is -

Tried to create an alias that targets d123rk29d0stfj.cloudfront.net., type A in zone Z3BW3XHLEBEA2Z, but the alias target name does not lie within the target zone

Thanks for reading, cheers

1

1 Answers

3
votes

So... of course that once Iv'e decided to post my question I found an answer lol.

According to the documentation, CloudFront HostedZoneId value MUST be Z2FDTNDATAQYW2.

Hope it might help anyone in the future, thanks.