-
-
Save guitarrapc/76355bdb8223612431b1 to your computer and use it in GitHub Desktop.
# Initialize | |
$resourceSubDomainName = "sample-subdomain" | |
$zoneName = "contoso.local" | |
$hostedZone = Get-R53HostedZones | where Name -eq $zoneName | |
# Set ResourceRecordSet | |
$resourceName = $resourceSubDomainName + "." + $zoneName | |
$resourceRecordSet = New-Object Amazon.Route53.Model.ResourceRecordSet | |
$resourceRecordSet.Name = $resourceName | |
$resourceRecordSet.Type = "A" | |
$resourceRecordSet.ResourceRecords = New-Object Amazon.Route53.Model.ResourceRecord ("192.168.0.100") | |
$resourceRecordSet.TTL = 300 | |
$resourceRecordSet.Weight = 0 | |
# Set Action | |
if (((Get-R53ResourceRecordSet -HostedZoneId $hostedZone.id).ResourceRecordSets | where Name -eq $resourceName | measure).Count -eq 0) | |
{ | |
$action = [Amazon.Route53.ChangeAction]::CREATE | |
} | |
else | |
{ | |
$action = [Amazon.Route53.ChangeAction]::UPSERT | |
} | |
# Set Change | |
$change = New-Object Amazon.Route53.Model.Change ($action, $resourceRecordSet) | |
# Execute | |
Edit-R53ResourceRecordSet -HostedZoneId $hostedZone.Id -ChangeBatch_Change $change |
Excellent - helped me too. thanks!
I get this error when running locally to test. any idea why?
"Get-R53ResourceRecordSet : Request object does not have required field HostedZoneId set"
@goalautomation Did you ever figure out your error? I am getting the same issue.
Question...
I'm using part of your script in one I have to update numerous records, and for the most part, it's working. The only thing I'm running into is that the UPSERT is inserting an additional IP into a record set. Do you know how to remove this extra IP from a record with the AWS PowerShell module? I'm trying to use the Amazon.Route53.Model.Change.ResourceRecordSet.ResourceRecords.Remove method, but it's not working. I know I'm missing something from the docs, and hoping someone here can point me in the right direction.
This was amazing! I am so grateful you published this.
Thanks again!
This script was very helpful! For some reason I was getting the error below but I just removed line #13 "$resourceRecordSet.Weight = 0" and I was able to get my record created in Route53.
Thank you!
Error I had: