I ran into an error the other day while using AWS Tools for Powershell to bulk update Route53 DNS records. Looking back now it was obvious, but this post should get the error into Google / DuckDuckGo for anyone else searching.

The error was:

Edit-R53ResourceRecordSet : Invalid request: Expected exactly one of [AliasTarget, all of [TTL, and ResourceRecords], or TrafficPolicyInstanceId], but found more than one in Change with [Action=CREATE, Name=sample.example.com., Type=A, SetIdentifier=null]

Right now you probably have a script that looks something like this (example mostly from the AWS Powershell Docs):

# Sample A record
$change1 = New-Object Amazon.Route53.Model.Change
$change1.Action = "CREATE"
$change1.ResourceRecordSet = New-Object Amazon.Route53.Model.ResourceRecordSet
$change1.ResourceRecordSet.Name = "sample.example.com."
$change1.ResourceRecordSet.Type = "A"
$change1.ResourceRecordSet.TTL = 60 # Note this line here
$change1.ResourceRecordSet.AliasTarget = New-Object Amazon.Route53.Model.AliasTarget
$change1.ResourceRecordSet.AliasTarget.HostedZoneId = "Z1111111111111"
$change1.ResourceRecordSet.AliasTarget.DNSName = "example-load-balancer-1111111111.us-east-1.elb.amazonaws.com."
$change1.ResourceRecordSet.AliasTarget.EvaluateTargetHealth = $true

$change2 = New-Object Amazon.Route53.Model.Change
# ... etc - Build your other record changes

$params = @{
    HostedZoneId="Z222222222"
	ChangeBatch_Comment="..."
	ChangeBatch_Change=$change1,$change2
}

Edit-R53ResourceRecordSet @params

The trick here is that records pointing to an AliasTarget don’t need a TTL!

A configurable TTL doesn’t exist for records pointing to an AWS AliasTarget (such as a load balancer) as you don’t get to control the TTL.

Here is the excerpt from the Route53 docs:

If an alias record points to an AWS resource, you can’t set the time to live (TTL); Route 53 uses the default TTL for the resource. If an alias record points to another record in the same hosted zone, Route 53 uses the TTL of the record that the alias record points to.

Hope that helps - finding this in Google sure would have saved me 15 minutes, even though the error message makes it super obvious in hindsight…

There are a lot of links for the AWS Tools for Powershell, so here are direct links to the useful things: