Search code examples
dnsamazon-route53.net-core-3.1

Await for ChangeResourceRecordSetsAsync hangs forever when trying to create Route53 DNS record


I am trying to create a TXT record in AWS Route53, but while awaiting the call, it will never complete.

The record is not being created in the hosted zone. The account has the correct permissions which I tested using the AWS CLI.

I am able to list hosted zones as also shown in the code below.

public static async Task CreateRecordAsync()
{
    var route53Client = new AmazonRoute53Client("<myAccessKey>", "<mySecretKey>", RegionEndpoint.EUCentral1);

    var test = new ListHostedZonesByNameRequest();
    var testResponse = route53Client.ListHostedZonesByNameAsync(test);

    foreach (var zone in testResponse.Result.HostedZones)
    {
        Console.WriteLine($"{zone.Name}{zone.Id}");
    }

    var response = await route53Client.ChangeResourceRecordSetsAsync(new ChangeResourceRecordSetsRequest
    {
        ChangeBatch = new ChangeBatch
        {
            Changes = new List<Change> {
                new Change {
                    Action = "CREATE",
                    ResourceRecordSet = new ResourceRecordSet {
                        Name = "my.domain.net",
                        Type = "TXT",
                        TTL = 60,
                        ResourceRecords = new List<ResourceRecord> 
                        { 
                            new ResourceRecord 
                            { 
                                Value = "test txt value" 
                            } 
                        }
                    }
                }
            },
            Comment = "Test Entry"
        },
        HostedZoneId = "Z2Q***********"
    });
}

Solution

  • The problem was that the TXT record had to be enclosed in double quotes. I just had to catch the correct exception.

    try
    {
        ....
        ChangeResourceRecordSetsResponse recordsetResponse = 
            await route53Client.ChangeResourceRecordSetsAsync(recordsetRequest);
        ....
    }
    catch (InvalidChangeBatchException ex)
    {
        Console.WriteLine(ex);
    }
    

    Which means that I should have constructed my record like this using.

    ResourceRecordSet recordSet = new ResourceRecordSet
    {
        Name = chosenDomain,
        TTL = 60,
        Type = RRType.TXT,
        ResourceRecords = new List<ResourceRecord> 
        { 
            new ResourceRecord 
            { 
                Value = "\"This is my test txt record\"" 
            } 
        }
    };