Created
February 3, 2015 06:28
-
-
Save guitarrapc/76355bdb8223612431b1 to your computer and use it in GitHub Desktop.
Amazon Route53 resource record set PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
@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!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I get this error when running locally to test. any idea why?
"Get-R53ResourceRecordSet : Request object does not have required field HostedZoneId set"